Optimizing Plugins: Cache Results on a Larger Scale?
Surely many of you have read the article on the Wiki about how saving results helps optimize your plugins. Now I'm wanting to know what you guys think about applying such method on a larger scale (sort of).
Let's say I have the following code: Code:
So the idea would be to: 1. Cache the CVar on new round events (since there is no forward for detecting the exact moment it's changed). Then we can just add to the plugin's documentation: "CVar changes will take effect after a new round". Usually, end-users won't be upset by this restriction IMO. 2. Cache whether the user is a bot on client connect forwards (since the "bot" property will only change whenever a new player joins the server). 3. Cache whether the player is alive on client spawn, death, and disconnect events (since... well you get the point). So this is what the final code would look like: Code:
So what do you think? Is this really an optimization? If so, is it worth it the work? And when? |
Re: Optimizing Plugins: Cache Results on a Larger Scale?
I'd reckon that in this case, if it's faster, it'd be that much better. With that in mind, you could do some benchmarks to see which method is faster and by what degree.
Looking forward to your findings. :wink: |
Re: Optimizing Plugins: Cache Results on a Larger Scale?
Quote:
Test 1 - FM_PlayerPreThink forward Normal: Code:
date: Thu Mar 19 23:26:04 2009 map: de_dust2Code:
date: Thu Mar 19 23:26:04 2009 map: de_dust2Normal: Code:
date: Thu Mar 19 23:42:00 2009 map: de_dust2Code:
date: Thu Mar 19 23:42:00 2009 map: de_dust2* Special thanks to sawce for his magnificent profiler. |
Re: Optimizing Plugins: Cache Results on a Larger Scale?
One thing you should not forget though is that the extra work of that approach only brings benefits on forwards called multiple times a second. I don't doubt we'll see people caching everything for a 10s task, like it happened with the fakemeta-conversion fad.
|
Re: Optimizing Plugins: Cache Results on a Larger Scale?
If I'm doing the calculations correctly...
FM_PlayerPreThink: The optimized version is 14.38 times faster overall than the normal version. Normal version spends an average of 24.54 microseconds per call. Optimized version spends an average of 1.71 microseconds per call. FM_AddToFullPack: The optimized version is 8.04 times faster overall than the normal version. Normal version spends an average of 8.37 microseconds per call. Optimized version spends an average of 1.04 microseconds per call. So, this technique reduces the time spent by roughly one order of magnitude. I love to see this kind of data ^___________________^. Thanks, MeRcyLeZZ! In the end, we're dealing with microseconds. How noticeable will this optimization be for the end user? |
Re: Optimizing Plugins: Cache Results on a Larger Scale?
Quote:
|
Re: Optimizing Plugins: Cache Results on a Larger Scale?
MeRcyLeZZ where did you got this analyzing tool?
|
Re: Optimizing Plugins: Cache Results on a Larger Scale?
|
Re: Optimizing Plugins: Cache Results on a Larger Scale?
should be added to the efficiency tutorial!!!
i already used it but i couldnt imagine that there is such a difference in using it in fast ticking things such as preThink :O |
Re: Optimizing Plugins: Cache Results on a Larger Scale?
Quote:
Will do it these days :). |
| All times are GMT -4. The time now is 09:01. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.