0Pricing
Android Academy · Lesson

Measuring Performance

Profilers, traces and benchmarks.

Measure Before You Optimize

The golden rule of performance work: measure first, guess never. Human intuition about what is slow is almost always wrong.

In this lesson you will learn the tools Android gives you to see performance: the profilers, system traces, and microbenchmarks. Once you can measure, every optimization becomes a data-driven decision instead of a hunch.

  • Profilers show CPU, memory and energy in real time.
  • System traces reveal exactly where each frame's time goes.
  • Benchmarks give repeatable numbers you can compare across builds.

The 16ms Frame Budget

On a 60Hz screen, the system draws a new frame every 16.67ms. If your app cannot prepare a frame in that window, the frame is dropped and users perceive jank (stutter). On 120Hz devices the budget shrinks to about 8ms.

Performance work is really about staying inside this budget. The comment below shows the math you keep in your head.

// Frame budget math
// 60 Hz  -> 1000ms / 60  = 16.67ms per frame
// 90 Hz  -> 1000ms / 90  = 11.11ms per frame
// 120 Hz -> 1000ms / 120 =  8.33ms per frame
//
// Exceed the budget on the UI thread = a dropped frame = visible jank.
fun frameBudgetMs(refreshHz: Int): Double = 1000.0 / refreshHz

fun main() {
    println("60Hz  -> %.2f ms".format(frameBudgetMs(60)))
    println("120Hz -> %.2f ms".format(frameBudgetMs(120)))
}

All lessons in this course

  1. Measuring Performance
  2. Taming Recomposition
  3. Memory Leaks and Fixes
  4. Startup and Baseline Profiles
← Back to Android Academy