Raised This Month: $32 Target: $400
 8% 

Solved What is more efficient?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-20-2016 , 13:43   What is more efficient?
Reply With Quote #1

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.
__________________

Last edited by luki1412; 09-23-2016 at 18:42.
luki1412 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-20-2016 , 14:13   Re: What is more efficient?
Reply With Quote #2

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.
__________________
Chaosxk is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-20-2016 , 14:27   Re: What is more efficient?
Reply With Quote #3

Quote:
Originally Posted by Chaosxk View Post
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.
__________________
luki1412 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-20-2016 , 14:28   Re: What is more efficient?
Reply With Quote #4

It's meaningless to "cache" non-string ConVars. As far as I know, SM does this cache for you in the background.
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-20-2016 , 14:51   Re: What is more efficient?
Reply With Quote #5

Quote:
Originally Posted by KissLick View Post
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?
__________________
luki1412 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 06-20-2016 , 14:58   Re: What is more efficient?
Reply With Quote #6

Quote:
Originally Posted by luki1412 View Post
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.
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 06-20-2016 , 20:04   Re: What is more efficient?
Reply With Quote #7

I cache all my cvars and hook changes to update the cache.
__________________
Neuro Toxin is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-20-2016 , 21:21   Re: What is more efficient?
Reply With Quote #8

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.
__________________

Last edited by ddhoward; 06-20-2016 at 21:22.
ddhoward is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 06-21-2016 , 06:14   Re: What is more efficient?
Reply With Quote #9

Quote:
Originally Posted by ddhoward View Post
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.
__________________
luki1412 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:47.


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