🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[PATCH] Compiler performance improvements

Started by
5 comments, last by WitchLord 10 years, 7 months ago
We recently passed the 6 second mark for compiling all our scripts in the debug build of our game. Waiting 6 seconds every time you want to test out a new change or for checking whether something compiles was getting a pain, so we threw a profiler at the angelscript script compiler to see if there were any bottlenecks we could fix.

Most of our eventual performance improvement came from changing the way we handled/injected shared code, which reduced the amount of compiled code by about half (with a similar speed improvement), but we did find some things that you might be interested in, the biggest being a major speed improvement to keyword tokenization.

Firstly, compiling angelscript with gcc is currently broken, compile-gcc.patch fixes it. asBC_DWORDARG was being used as an lvalue on as_restore.cpp:3975, I changed it to use the same format as the other asBC_*ARG macros so that that's not invalid.

The biggest bottleneck in compilation for us was asCTokenizer::IsKeyWord, which was taking up over 21% of the total compilation time. I changed it from repeated binary string searches on a map to use a lookup table based on the first character - this is tokenizer.patch. It could probably be improved even further by using something like gperf, but since this shot it down to about 1% of the compile time I moved on to other things.

The last patch maps.patch is sort of a mix match of things related to eliminating linear searches from identifier lookups throughout the compiler. Feel free to pick and choose any or none of it, most of this was just us (Andrew Ackermann and me) slapping maps or symbol tables in various places.
Advertisement

Thanks a lot. I'll review the patches carefully and incorporate them into the SVN as soon as possible.

Regards,

Andreas

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

Wow exciting, I love to hear about optimizations, GCLucas can I ask approximately how many KB or lines of code of Angelscript do you have that it took 6 seconds to compile?

If the load time was 6 seconds, what is it now after these optimizations?

Might I recommend that you consider using the release version of your game to test scripts for compile errors? Compile errors should be reported just as well in release as debug mode and asserts can be enabled in release mode if desired.

Alternatively, you could also consider loading the last (date modified) saved script first for compiling, This would result in compile errors being found near instantly.

Lead Coder/Game Designer for Brutal Nature: http://BrutalNature.com

GGLucas and I both work on the project that had the (not really very) long compile times. The 6 seconds was in release, and is the compile time for ~1.1MB of scripts. Post-optimization is closer to 1.5 seconds, but some of that is from improvements specific to our use of AngelScript. Debug for me was taking upwards of 28 seconds to compile by comparison.

We have tried to use bytecode saving and loading, but it doesn't work with something in our codebase that we've yet to find a solution to.


but it doesn't work with something in our codebase that we've yet to find a solution to.

What is wrong with you code if they can't save and load?

The bytecode saving or loading has a subtle bug with shared code that we've never been able to isolate. It disappears whenever the codebase gets small enough to reasonably test.

I've finished incorporating these improvements into the WIP version. (revision 1779).

With the improvements I see an average improvement of around 30% in the compilation times.

I didn't include the changes as-is, so when you pick up the new version you'll will not see exactly the code you provided, but you should see that all the improvements you made has made it into the code, and in some cases I made further improvements on top of them.

Thanks,

Andreas

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