Wednesday 21 April 2010

More Optimisations

Talking about optimisations isn't especially exciting, though recent changes have been crucially important to making larger, more complex games viable on XAGE. The super-secret game, for instance, wasn't running at all well on the 360. After a productive weekend it now performs rather admirably, which is a major relief.

Engine - Load Times

Xml serialization is great, but - cripes - it's incredibly slow on the xbox. The main game content was taking in the region of 60 to 70 seconds to load, which might be passable for a Triple-A title but very undesireable for an Indie Game with a short time period in which to make a good impression.

The Automatic XNB serialisation built into Xna Game Studio wasn't really an option, and would have added a an extra layer of complexity to the publishing process. The only remaining solution was to write all data to a binary stream, which is blazing fast and supported on all platforms, but has obvious downsides:
  • You have to write load & save code for EACH class you want persist (at 70+ classes, this is a huge job).
  • Each time you change a class, you also have you to update and test the IO code (adding a painful maintenance overhead).
The eureka moment came from realizing that I could write a routine to generate the C# IO code automatically, and use this to extend my existing classes. I've written a summary of my solution on the Xna Forums.

The load time is now down to about 10 seconds, including all the initial graphics and audio - much better!

Engine - Garbage Collection

As mentioned previously, the X360 garbage collector is also horrifically slow. The super-secret game was causing XAGE to generate 1mb of garbage a second, causing a stuttering that was particularly noticeable when moving the cursor.

Using Collection Pools for the scripting routines and removing some sloppy CopyTo commands have reduced this to about 120k per second, meaning the GCs now occur once every 8 or 9 seconds and are less noticeable. I'll return to this in the future and should be able to reduce it further still.

Editor - AGS Conversions

The scripts are now processed in smaller chunks, speeding up some of the string manipulations dramatically. The HitchHiker's demo, quite frankly, used to take an absolute age to convert to XAGE and now the whole thing takes less than half a minute.

No comments: