Is it bad to call GetCVar every tick?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Nash
 
 
Posts: 17481
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Is it bad to call GetCVar every tick?

Post by Nash »

I have a unified UI drawer class that draws stuff to the screen tinted/overlayed with custom RGB values that are saved per-user... it calls GetCVar every tick to get the colours. My question is if this is bad programming practice? I can't seem to measure any performance issues but I'm curious if getting a CVar value every tick might be bad or not... I mean, does GetCVar cause hard disk wear and tear from having to read the user's INI?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49211
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Is it bad to call GetCVar every tick?

Post by Graf Zahl »

Like with everything it depends on how often you call it each tick. The main issue in this case is that it performs a linear search over the existing CVar's which is not particularly optimal.
Do a few more such searches and it will eventually have an impact on performance.
User avatar
Eliot_L
Posts: 38
Joined: Thu Mar 08, 2018 3:40 am

Re: Is it bad to call GetCVar every tick?

Post by Eliot_L »

Good to know. We were having a discussion about caching CVar objects over here. I'm doing it in my WAD but apparently this is only safe to do for transient CVars.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Is it bad to call GetCVar every tick?

Post by Apeirogon »

Nash wrote:I can't seem to measure any performance issues
This
lag.wad
and sunlust map 24, or any other that have more than 1000 monsters.

Unles you have gaming computer, which can fried eggs to you at videocard...mmm refined taste of nvidia chipset...
You do not have the required permissions to view the files attached to this post.

Return to “Scripting”