On XBOX 360 Garbage Collection and Optimisations

Recently when testing general performance of one iteration of the planet generation code I was surprised to see the performance of the XBOX version of my code to be significantly worse than the PC version, so I started to poke around a bit. After reading a few articles about garbage collection on the Xbox framework one big issue stood out from the rest:

The XBOX 360 runs on a version of the Compact Framework which, like the regular CF, performs a garbage collection after 1MB of memory has been allocated without the concept of Generations.

That basically means that whilst the garbage generated by my code on the PC is collected more efficiently and without noticing it’s impact on performance, on the XBOX it was running a full collection at least once every 2-3 seconds which is crazy.

So I started to refactor key portions of the terrain patch system which dealt with the creation of the vertex arrays and usage of the effects. Whilst I was in this refactoring mood I also optimised a lot of the Vector3 & Vector3D method calls to use the ref version.

For example, previously:

 Old

Now:

 New

The result is that GC’s were being performed substantially less and as a result, I gained about 200fps on the XBOX version, and around 300FPS on the PC version. I did both types of optimisations at the same time so its hard to see which one had more impact across the board, but definitely on the XBOX, reducing the GC runs resulted in a much smoother framerate.

More information on the XBOX 360 version of the CF can be found here:

http://blogs.msdn.com/netcfteam/archive/2006/12/22/managed-code-performance-on-xbox-360-for-the-xna-framework-1-0.aspx

It’s a little old but the core concepts still stand true.

Also Shawn Hargreaves has some very good information on XBOX GC:

Shawn Hargreaves: How to tell if your XBOX garbage collection is too slow
Shawn Hargreaves: Twin paths to garbage collector nirvana


Tags:
Categories: XNA

31 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Comments

July 2. 2010 04:07

pingback

Pingback from spacedjase.com

spaced jase | How to eliminate frame-by-frame Garbage Generation using CLR Profiler

spacedjase.com