Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Performance Optimisations for Android

Short summary from

  • 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
You can’t perform that action at this time.