AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved What is more efficient? (https://forums.alliedmods.net/showthread.php?t=284169)

luki1412 06-20-2016 13:43

What is more efficient?
 
Im trying to optimize my plugin but Im not sure whats more efficient:
I need to get values from cvars but I have to do it very often (player spawn and ongameframe).

So whats better:

1. getting cvar values from cvars in OnPluginStart and saving them in global variables so I can just use the global variables and hook the convar changes so when they get changed I modify the global variables.

or

2. no global variables for cvars, but using getconvarint, getconvarfloat, getconvarstring and getconvarbool every time I need to access the cvar variables.

Chaosxk 06-20-2016 14:13

Re: What is more efficient?
 
Well this is what GetConVarInt does: https://github.com/alliedmodders/sou....cpp#L335-L348

From that i would guess it will be slightly better to cache it in global variables, especially if you need it every frame.

luki1412 06-20-2016 14:27

Re: What is more efficient?
 
Quote:

Originally Posted by Chaosxk (Post 2429114)
Well this is what GetConVarInt does: https://github.com/alliedmodders/sou....cpp#L335-L348

From that i would guess it will be slightly better to cache it in global variables, especially if you need it every frame.

That's what I thought, thanks.

KissLick 06-20-2016 14:28

Re: What is more efficient?
 
It's meaningless to "cache" non-string ConVars. As far as I know, SM does this cache for you in the background.

luki1412 06-20-2016 14:51

Re: What is more efficient?
 
Quote:

Originally Posted by KissLick (Post 2429120)
It's meaningless to "cache" non-string ConVars. As far as I know, SM does this cache for you in the background.

So what are you suggesting?

KissLick 06-20-2016 14:58

Re: What is more efficient?
 
Quote:

Originally Posted by luki1412 (Post 2429127)
So what are you suggesting?

Cache only string ConVars, because getting their value is a pain in the a**. For int, float and bool ConVars, just use GetConVar*** functions.

Neuro Toxin 06-20-2016 20:04

Re: What is more efficient?
 
I cache all my cvars and hook changes to update the cache.

ddhoward 06-20-2016 21:21

Re: What is more efficient?
 
AFAIK, Sourcemod caches cvars on its own; other than to save calls to GetConVarString, caching cvars is unnecessary.

My Friendly Mode plugin once cached all its cvars in such a manner. It was hell to maintain, and ultimately unnecessary as I later found out.


Further, the new syntax seems to discourage caching in this manner, with the cool .IntValue .FloatValue and .BoolValue properties.

luki1412 06-21-2016 06:14

Re: What is more efficient?
 
Quote:

Originally Posted by ddhoward (Post 2429230)
AFAIK, Sourcemod caches cvars on its own; other than to save calls to GetConVarString, caching cvars is unnecessary.

My Friendly Mode plugin once cached all its cvars in such a manner. It was hell to maintain, and ultimately unnecessary as I later found out.


Further, the new syntax seems to discourage caching in this manner, with the cool .IntValue .FloatValue and .BoolValue properties.

Thank you for this info.


All times are GMT -4. The time now is 18:28.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.