XNA 4.0 Performance Considerations
A few days ago I stumbled upon an excellent talk by Shawn Hargreaves at Mix10. You can view it online, or download a high-def version of the video and PPT slide deck from here.
If you like what you see, you can get the demo Shawn shows from here.
So that said, a few points of my own to add:
- WP7 does not support unsafe. this takes away a lot of CPU optimizations that you could do on PC and XB360
- WP7 apps will support 512mb of ram use, so better to precalculate and use more ram
- XB360’s GC will take aprox 14ms to inspect 100,000 objects. We better bet that WP7 will take longer.
VS2010: IDE performance is laggy (how to improve)
I’ve seen some sluggish performance in the VS2010 ide, and thought i’d share how i improved performance:
- Go to Tools —> Options drop-down menu
- Click Environment —> General from the list
- in the VisualExperience box:
- Uncheck “Automatically adjust visual experience based on client performance”
- Uncheck “Enable rich client visual experience”.
- Press OK then restart visual studio.
That doesnt seem to make everything super fast, but it does help make it not-so-slow =D
-JasonS
vs2010 resources
here’s some resources i gathered on visual studio 2010 (new features + tricks)
moving to xna4
Now that the Xna4 Beta is out, our team decided to take the plunge.
A few things to be aware of
- Xna4 is VS2010 only.
but xna4+vs2010 can live side-by-side xna3.1+vs2008
- Xna4CTP uninstall is a PoS (broken)
use the XNA Game Studio cleanup tool if you run into problems uninstalling any version of XNA. (you will)
- Resharper 4.5 does not work on VS2010
upgrade to 5.0!
- Resharper 5.0 doesnt really work on VS2008
a lot of key commands are broken :(
- XNA4 contains breaking changes.
especially in rendering. hope you like refactoring.
Now is an ideal time to upgrade:
we are rewriting our rendering system, so best to do this as part of our shift to xna4, especially looking at a “fixed function fallback” system.
We already did some tests to make sure our code isnt a nightmare to port, so good times.
-JasonS
critical section perf trick: reducing casts
If you’ve ever had to do something like this:
if(someObject is MyType)
{
var myClass = someObject as MyType;
myClass.DoStuff();
}
then give this a try in critical (perf) sections instead:
var myClass = someObject as MyType;
if(myClass!=null)
{
myClass.DoStuff();
}
it reduces your cast operations to 1 instead of two, and offers similar readability.
enjoys
-JasonS
incremental redesign of Novaleaf Engine
we are about 2/3 through our post e3 “fix up” month, and thought i’d share a tiny bit on what we are doing:
What was wrong with our E3 demo:
The e3 demo was pretty, but had some technical issues:
- world objects were atomic only:
this means buildings were a single, opaque object. not because we only support atomic objects, but I didn’t want to spend time finishing the implemenation of composite objects until we were sure about the entire workflow, which leads to:
- the game object system was not extensible:
our “Element” system (atomic and composite) was high performance, but extending it was not easy: a single manager class that needed to be extended as a monolithic singleton. not good for supporting various game object categories.
- the visualization system was a nightmare:
well not a nightmare really, the system worked, but was overly complex architecture, plus difficult to extend. We have a deferred rendering pipeline, and the rendering system was designed with only that in mind. So extending rendering for use with particles, etc was difficult.
- rendering suffered performance issues:
CPU stalls waiting for the GPU, plus mysterious cpu spikes of up to 30ms shows significant risk in the current rendering architecture
- misc system design issues:
the particle system and physics system were fairly poorly designed (lacked required features) and need some architecture changes
Tomorrow, I’ll start talking about the steps we are taking to resolve these issues.
-JasonS
.Net SortedSet<T> is almost awesome
I’m working on rendering infrastructure right now, and came up with an idea for how to store and sort renderPackets based on criteria efficiently using a binary heap.
What’s the BCL got?
That’s great, but I remembered seeing an MSDN article on a new BCL collection called SortedSet<T>
Nice features
It’s pretty sweet. As this CodeProject article describes, it has a neat Sub-Tree filter that can be used to partition the view, and it has good CPU performance with O(LogN) time.
Not good enough
Unfortunately, it seems like the BCL team is lapsing a bit on QC: SortedSet<T> is implemented using classes for Nodes, not structs. This has massive, harmfull, repercussions on CF.NET, and therefore makes SortedSet<T> unusable for a core, high-performance game system.
What’s to be done?
Thankfully, I can salvage the goodness of SortedSet’s features by implementing my own version of the class using a struct Node[] array as storage. It’ll take a little time, but I can use the BCL API’s as reference, and that will give me a SortedSet that offers good CPU and GC performance.
-JasonS
Everything you ever wanted to know about CF.NET performance