bjornharrtell/wastelands — Issue #9: Optimizing calculation of tileIndex and tilePixelOffset in Screen.render
Author: johansjoberg
Created: 2012-01-04 10:21:23+00:00
State: open

Try to optimize the calculation of tileIndex and tilePixelOffset in Screen.render method. When investigating it seems that on some old phones at least there can be a big benefit of doing things without floating-point calculations or modulus.

Quote from 'http://developer.android.com/guide/practices/design/performance.html':
As a rule of thumb, floating-point is about 2x slower than integer on Android devices. This is true on a FPU-less, JIT-less G1 and a Nexus One with an FPU and the JIT. (Of course, absolute speed difference between those two devices is about 10x for arithmetic operations.)

In speed terms, there's no difference between float and double on the more modern hardware. Space-wise, double is 2x larger. As with desktop machines, assuming space isn't an issue, you should prefer double to float.

Also, even for integers, some chips have hardware multiply but lack hardware divide. In such cases, integer division and modulus operations are performed in software — something to think about if you're designing a hash table or doing lots of math.