Intro To Android (Workbook 2)

Performance

In this chapter we'll cover the basics and tools available for performance tuning. We'll use our application as a basis for the benchmarking and subsequent improvements suggested in this chapter.

Android Performance

Each application is different and will have unique performance considerations, but the general classes of performance issues are:

  1. Memory leaks
  2. View inflation
  3. Scrolling performance
  4. Object creation
  5. Long operations on UI thread
  6. Bitmaps

The tools we'll be using to find issues are covered in depth in this chapter. You should also check out Android's performance best practices for more information.

Premature Optimization

You could spend endless hours fine tuning random bits of your application, but what's the point if it won't make a perceptible difference to your users?

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, [they] will be wise to look carefully at the critical code; but only after that code has been identified.

Donald Knuth

Often the effort of optimizing can lead harder to read code, which is less maintainable. It's important to know what you are optimizing and why it's business critical before tackling that section of the application. It's best to start with a benchmark to measure against to make the biggest impact in your application.

Perceived vs. Actual Performance

Even if your application is slow, if you give visual feedback to your users instead of blocking the entire UI (like with a spinner while you load data), they will think your application performs better than it actually does.

In the reverse, if your application is really fast but is slow to respond to user input (e.g. a slow button press), they will perceive your application as slower than it actually is!