XNA Performance and the SpriteBatch
Over the last few days I have been helping someone with a small application and some performance issues with it. When looking at the code I found that the application was calling several sprite batches. To test the effects of running multiple batches I put together a base application that did nothing fancy.
The basic layout and functions in the application included the default application template with events added to the base for the loading of managed and non managed resources. To test the performance I added three sprite batches (background, main, and UI). Testing was done by disabling all of then and building the app, then in turn adding one in between builds. While the application was running I just did a simple check on the processes tab in the task manager and recorded the memory usage of the application.
When testing I found that each time I added another sprite batch to the code the memory increased in the usage...
- 0 sprite batches configured - 16920
- 1 sprite batch configured - 19744
- 2 sprite batches configured - 20172
- 3 sprite batches configured - 20640
When testing the system all of the results where expected and the main purpose of the application and the tests was to prove a point. In summary we really need to look at our applications and make sure that we are only making calls that are needed. In the case of the sprite batches, why do we have multiple batches? Can we do it all with just the one batch?
When developing with MDX I used to used multiple calls to the sprites, but during the stages of the managed DirectX system a 2d Sample was released that showed a method to batch the sprites. From that point on I began to batch the sprites into the one call... and now with XNA I do the same.
On a Side note I am still working on Setting up an Australian based XNA User group, those who are interested can contact me through my site www.virtualrealm.com.au.
Cross Post from
Virtual Realm - Mykre's Space