The game Battle Tank was optimised for performance. You can find the complete source code here.
Action taken |
Time saved after optimisation (ms per frame) |
Reused objects instead of allocating new (In this case: reused HUD) |
16 |
Removed synchronous reference to flash memory in a loop (In this case writing some state data to RMS) |
28 |
Turning ON ProGuard decreases the size of the JAR by 4% (889 -> 852 kB) and RAM usage dropped from 161 kB to 138 kB (14%). In this case the application graphics are the primary drivers of the JAR size, and ProGuard cannot shrink this.
As a test, we let the accelerometer sensor drive the Battle Tank main loop instead of decoupling it as a separate thread. The frame rate decreased from 13.5 frames per second (fps) to 11.6 fps. For a more detailed example of not letting the speed of a sensor drive your animation loop, see Episode 19: Motion Input.