Why was "Avoid Enums Where You Only Need Ints" removed from Android's performance tips?
the original version of that document was just a bunch of prejudices. it's been rewritten to only contain facts backed up by actual benchmarks, and it's updated as the VM is updated. you can find the various benchmarks -- plus some of the benchmarks we use to optimize the core libraries -- at http://code.google.com/p/dalvik/.
A guess:
- Gigahertz CPUs like Hummingbird and Snapdragon are now common, and the small-code small-memory requirements which originally constrained the Dalvik VM are no longer as true.
- Every shipping device uses the JIT (new to 2.2). The enum’s class initializer will run faster, the values might be treated as JIT-time constants, and the JIT might well have special support for streamlining enum classes.
- Code which is really performance-sensitive uses the NDK, which was still new and unpolished when Android 1.5 was released. The NDK in 2.3 supports native activities, which allows for near-fully unmanaged games.
Thus, for the comparatively mundane requirements of a GUI app, the development-time benefits of enums far outweigh the extra runtime cost.
Elliott Hughes offers more details about the documentation rewrite on his blog: http://elliotth.blogspot.com/2010/09/java-benchmarks.html
The second half of the post explains that every claim on the Performance doc is now backed up with benchmarks. Previous versions of the doc apparently contained unverified claims, like, "Avoid enums because they are too expensive."