Skip to content
Commitwise
Menu

Why does a Compose screen recompose too much, and how do you fix it?

AndroidSenior

In shortRecomposition runs when state a composable reads changes, and skipping depends on parameters being stable and equal. Over-recomposition usually comes from reading fast-changing state too high up, unstable parameters (mutable classes, plain List from other modules, lambdas capturing unstable values), or new objects created every time. Measure first, then narrow state reads and stabilize parameters.

Model answer

How it works: a composable recomposes when state it read changes. During recomposition, a call can be skipped if all its parameters are equal to last time and considered stable. With strong skipping mode (the default in recent Kotlin Compose compiler versions), unstable parameters are compared by instance, and lambdas are remembered automatically, so most skipping issues now come from new instances and broad state reads.

Common causes:

  • Reading fast-changing state high up: reading scrollState.value or an animation value in a screen-level composable recomposes the whole screen every frame. Pass lambdas ({ scrollState.value }) and read in layout or draw (Modifier.offset { }, graphicsLayer { }).
  • New objects every recomposition: listOf(...), Modifier chains with new lambdas or formatters created in the body; hoist or remember them.
  • Unstable models: classes with var properties or mutable collections; prefer immutable data classes, kotlinx.collections.immutable, or a stability configuration file for classes from other modules.
  • Derived values: use derivedStateOf when a value changes less often than its inputs (show a button only when firstVisibleItemIndex > 0).
  • Lazy lists: stable keys and contentType so items are reused correctly.

Measure: Layout Inspector’s recomposition and skip counts, Compose compiler reports for stability, and Macrobenchmark with JankStats for real frame timing.

What they're looking for

How recomposition and skipping work, stability inference and strong skipping mode, deferring reads to layout or draw, derivedStateOf, keys in lazy lists, and measurement tools.

Common mistakes

  • Annotating everything @Stable without making it actually stable.
  • Optimizing without measuring recomposition counts.
  • Reading scroll or animation state in composition.

More android questions

Esc

Type to search the whole site.