Android Game Development Bottlenecks
Lately I’ve been working on a game for Android based devices as I believe in the Android platform and wanted to show it some developer support. In the few weeks I’ve spent with this project I’ve learned about some performance bottlenecks the hard way so I’m putting together a quick list of things to be aware of that may help out other Android game developers.
Memory allocations are slow
One of the worst things that will hurt performance are memory allocations. These will produce noticeable pauses when many or large objects are instantiated all at the same time, and if you are using Java collections like ArrayLists they will even slow down item enumeration in loops. Keep collections away from your main loop to keep speed up – this also ties into the next item:
Just like memory allocation, memory deallocation by Dalvik VM’s garbage collector will also affect performance. The main symptom of creating objects during your game loop or calculations will be regularly spaced jitters during executation. The garbage collector will run intermittently to clean up any objects that are no longer in use, how often this process occurs depends on how much memory is being left behind.
Java’s collections will also create and leave behind memory during add, remove, and even enumeration which are other good reasons to leave Java collections behind in favor of fixed size arrays.
Logcat is your friend!
The adb tool that’s installed by the Android SDK will let you view the live log being written by the connected device. Most importantly this will show garbage collection events and crash logs being written by your application which will point you at the line in your code that caused the exception.