Skip to content

Instantly share code, notes, and snippets.

@rkhmelyuk
Created October 11, 2011 12:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkhmelyuk/1277969 to your computer and use it in GitHub Desktop.
Save rkhmelyuk/1277969 to your computer and use it in GitHub Desktop.
Performance Optimisations for Android

Short summary from http://developer.android.com/guide/practices/design/performance.html

  • avoid creating objects if you don’t need them
  • avoid allocation memory if you can work without it
  • two parallel arrays of ints are also a lot more efficient than an array of (int,int) objects
  • array of ints is preferred than array of Integers
  • avoid creating short-term temporary objects if you can
  • make your method static. Invocations will be about 15%-20% faster. It's also good practice, because you can tell from the method signature that calling the method can't alter the object's state.
  • It's reasonable to follow common object-oriented programming practices and have getters and setters in the public interface, but within a class you should always access fields directly.
  • direct field access is about 7x faster than invoking a trivial getter
  • use static final for constants
  • prefer for-each loop
  • declare fields and methods accessed by inner classes to have package access, rather than private access
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment