Quote:
Originally Posted by georgik57
Any mod which gives a lot of health to players will trigger it a lot(for example zombie mods).
|
That's still not a lot.
get_pcvar_num is not an expensive operation: it's an O(1) time complexity operation(this is why we use pcvars over cvars, we don't need to iterate over the entire cvar list because we have a pointer and we can simply access the value that the pointer points to).
Reading the data from the variable that caches the cvar is also O(1) so if you are not trying to optimize that why are you trying to optimize something that's equivalent?
Truth be told, that's half the story. Since
get_pcvar_num is a native there's also some time spent in communicating between pawn and c++,
BUT it's nothing to worry about in the context of a
TakeDamage call. You could argue about caching O(1) natives if your forward was called per frame, but
TakeDamage is not and the fact that it may be fired for a few seconds on 16 zombies is literally nothing.
I don't know why people insist on doing worthless "optimizations" that will not provide any speed gain, require more coding time and hurt the user experience. Think about your algorithms and how the plugin is operating as a whole, not small insignificant things. A bad algorithm is a bad algorithm no matter how many cvars you cache, how many times you use static over new or how many bitsums are used over boolean arrays. On the other hand, a good algorithm remains good even if it doesn't cache cvars.
__________________