Jump to content
  • Advertisement
Sign in to follow this  
_orm_

The importance of Pre-Caching function handles.

This topic is 2816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know it was mentioned in the documentation that handles to functions should be pre-cached whenever possible, but I had absolutely no idea just how big of an impact it would have on performance.

As a bit of background, my engine has had a bottleneck that rears its ugly head when many objects are created and then destroyed.

One of the things I found out while I have been working is that when dealing with multiple instances of a particular class (such as the case with Mengi and the "Updatable") handles will differ on an instance-to-instance basis. As a result, in a fit of lazyness I would presume, I decided that I should grab the Update function ID for an Updatable script object on the fly in the update loop.

I am going to stop here and let the cachegrind results speak for themselves. Relevant part is highlighted in blue. The results with pre-caching are on the left, no pre-caching on the right.

profile.png (425 KB)

Share this post


Link to post
Share on other sites
Advertisement
I had similar drastic improvements when I started cashing all my GetTypeIdByDecl calls. I didn't do any benchmarking but I could tell just by running scripts that would previously make heavy use of these calls, just how much of an improvement in performance there was. Always makes me wonder why I didn't do this right from the start... Guess I've learned my lesson.

Kind regards,

Philip Bennefall

Share this post


Link to post
Share on other sites
Thanks for sharing.

The methods that are used to look up function id's and type id's etc are very heavy, as they need to do a lot of comparisons to find the correct function/type that is being looked for. Also, based on the fact that the results of these functions should be cached when possible I haven't really spent a lot of time in optimizing them. There are for example quite a bit of naïve linear searches and string comparisons in these functions at the moment.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!