This site is a testing version, but all data is shared with the live forum.


Raised This Month: $12 Target: $400
 3% 

Server Variables expense...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-03-2009 , 21:31   Server Variables expense...
Reply With Quote #1

Howdy,

I'm not extremely clued up on C++ and its intricate workings. I have a small question which I think may have a significant impact on speed if I'm correct.

Would I be correct in the assumption that if I have a local variable for each cvar which is set on change of each cvar that it would save a lot of expense when accessing each cvar? Now when I mean a lot, I mean a significant amount for 100+ cvars... I'm a devil for detail and I feel this might work albeit it would be quite a bit of work but doable all the same...
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Keeper
Senior Member
Join Date: Nov 2006
Old 09-03-2009 , 22:04   Re: Server Variables expense...
Reply With Quote #2

I'm no expert but here's how I view it logically. Three cases:

  1. CVars are read a lot, but not changed often - I would use a variable so you don't have to jump to the routine to get that value every time you read it.
  2. CVars are both changed and read often - Here it's a tradeoff. If you put in a callback to write to your variable, then you save on the reading. Otherwise you save by not having the callback, and just jump to the routine to get the value.
  3. CVars are changed more than read - I think here just getting the value would be better than adding the callback.
Of course this doesn't apply if you have special tests you need done on the CVar ( like making it read only ).

I could be really off base here, but based on what I have done my assumption is that either way you aren't going to notice a difference. Especially concerning the amount of code the server flies through 66 times per second.

Keeper
Keeper is offline
BAILOPAN
Join Date: Jan 2004
Old 09-03-2009 , 23:19   Re: Server Variables expense...
Reply With Quote #3

Premature optimization. Measure, then decide. Virtual call versus variable, without context or knowing where you are, is something measured in nanoseconds.
__________________
egg

Last edited by BAILOPAN; 09-03-2009 at 23:22.
BAILOPAN is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-03-2009 , 23:40   Re: Server Variables expense...
Reply With Quote #4

Hey thanks for the replies.

I understand it's a minute difference but I'm just considering all of the cvars I would be checking every tick it seems worth it for cvars accessed exceptionally often.

See I've still got a very VB head, and in VB calling anything in a class is a hell of a lot more expensive than accessing local variable.

If the virtual call is just a call to a pointer to a variable then it mightn't be so different. I'm still undecided.

To be honest there's a hell of a lot more optimisation I could do without worrying about these kinds of things but they matter too
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
BAILOPAN
Join Date: Jan 2004
Old 09-04-2009 , 01:38   Re: Server Variables expense...
Reply With Quote #5

Checking a numerical cvar value is probably like 5 instructions. On a 100 tick server there are 100 ticks per second. How many cvars checks are you performing per tick? Ten? A thousand? A hundred thousand?

Profiling is highly recommended.
__________________
egg

Last edited by BAILOPAN; 09-04-2009 at 01:44.
BAILOPAN is offline
Reply



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 23:31.


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