garbage-collectionxnaframe-ratexbox

Xna Xbox framedrops when GC kicks in


I'm developing an app (XNA Game) for the XBOX, which is a pretty simple app. The startpage contains tiles with moving gif images. Those gif images are actually all png images, which gets loaded once by every tile, and put in an array. Then, using a defined delay, these images are played (using a counter which increases every time a delay passes).

This all works well, however, I noticed some small lag every x seconds in the movement of the GIF images. I then started to add some benchmarking stuff:

http://gyazo.com/f5fe0da3ff81bd45c0c52d963feb91d8

As you can see, the FPS is pretty low for such a simple program (This is in debug, when running the app from the Xbox itself, I get an avg of 62fps). 2 important settings:

Graphics.SynchronizeWithVerticalRetrace = false; 
IsFixedTimeStep = false;

Changing isFixedTimeStep to true increases the lag. The settings tile has wheels which rotate, and you can see the wheels go back a little every x seconds. The same counts for SynchronizeWVR, also increases lag.

I noticed a connection between the lag and the moment the garbage collector kicks in, every time it kicks in, there is a lag...

Don't mind the MAX HMU(Heap memory usage), as this is takes the amount of the start, the avg is more realistic.

Here is another screen from the performance monitor, however I don't understand much from this tool, first time I'm using it... Hope it helps:

http://gyazo.com/f70a3d400657ac61e6e9f2caaaf17587


Solution

  • After a little research I found the culprit.

    I have custom components that all derive from GameComponent, and who get added to the Component list of the main Game class.

    This was one (of a total of 2) major problem, causing to update everything that wasn't needing an update. (The draw method was the only one who kept the page state in mind, and only drew if needed). I fixed this by using different "screens" (or pages as I called them), wich are the only components who derive from GameComponent.

    Then I only update the page wich is active, and the custom components on that page also get updated. Problem fixed.

    The second big problem, is the following; I made a class which helps me on positioning stuff on the screen, relative that is, with percentages and stuff like that. Parent containers, aligns & v-aligns etc etc. That class had properties, for size & vectors, but instead of saving the calculated value in a backing field, I recalculated them everytime I accessed a property. But calculating complex stuff like that uses references (to parent & child containers for example) wich made it very hard for the CLR, because it had alot of work to do.

    I now rebuilt the whole positioning class to a fully functional optimized class, with different flags for recalculating when necessairy, and instead of drops of 20fps, I now get an average of 170+fps!