Archive for the Programming Category

Frame-rate troubles on 360 XNA

Posted in Programming on March 25, 2008 by Bill

We had a good time profiling and optimizing the entire game on the day of the submission deadline :) 

A tip to any browsing XNA-ers out there: If you find your framerate sucks despite having already optimized the game systems you’d typically suspect of performance malarkey, turn to the c# garbage collector.  It’s got its own way of doing things… a very slow way of doing things… so it’s in your best interest to give it the least amount of work to do.  During those last few hilarious hours, we managed to cut back on garbage collection by eliminating foreach loops and other obvious failures on our part, like too many per-frame ”new”’s.  But, to our dismay, performance still sucked.

Dynamic casting in c# is evil:

SomeClass obj = baseClassPtr as SomeClass;

It’s incredibly slow - slower than most any RTTI system you could throw together yourself.  It’s a very powerful feature of C#, but use it sparingly, ESPECIALLY on 360.  Try to use Generics instead, or stick with one of the tried-and-true methods, like maintaining an enum or identifier in your base classes and C-style static casting:

switch( baseClassPtr.GetClassType() ) 
{
    case CLASSTYPE_SOMECLASS:
        SomeClass obj = (SomeClass)baseClassPtr;
        // etc…
}

That actually turned out to be the biggest performance win of the day over any of the garbage collection madness, which we spent the majority of our profiling efforts scrambling with.