While developing our new game, I stumbled upon what seemed to be a strange Mono/dalvik behavior.
We noticed with our new project that there were some serious hickups, even on devices performing very well (framerate drops from 60 to 45fps every 5-10 seconds).
Debugging the app revealed that these hickups are the consequence of a lot of Davlik GC_FOR_ALLOC and Mono minor (nursery) collections. There is something like one davlik collection every 5-10 seconds and one Mono collection every 30 seconds.
In order to identify the problem, I reduced the scope of the game, down to… the most minimal MonoGame example: the empty cornflower blue template. Launching it exposes the problem quite quickly.
I never noticed this on our previous project, probably because it was more memory intensive and that Mono & Davlik quickly promoted their heap size (hence, less frequent garbage collection). But it looks like low memory/memory efficient applications are impacted by small heaps barely promoted to bigger size. (But I’m no VM expert, so any comment is welcome.)
Profiling the cornflower blue template shows some garbage (mostly strings, char and byte, what seems to be StringBuilder buffer resizing work). Mono collects just a few hundred KB every 30sec, while Dalvik collects up to 5MB of strings/char every 10sec.
Strangely enough, it seems that the Mono collections happen also on iOS (every 10-30sec), but with a different garbage collector, I would assume more different results. But that may be my imagination, I haven’t thoroughly profiled the iOS build.
So, here are some questions, which may be a little naive with my VM knowledge:
- is this a normal behavior?
- if there’s so much Dalvik garbage, does it mean that Mono itself have leaks?
- I am tempted to boost the heap size manually, but that would not be effecient and would not get rid of garbage collection, just temper them?