Advertisement

The importance of Pre-Caching function handles.

Started by January 06, 2011 07:00 PM
1 comment, last by WitchLord 13 years, 10 months ago
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)
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
Advertisement
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement