Debug Compose Recomposition with Android Studio Layout Inspector
See exactly which Jetpack Compose nodes recompose when state changes, so you can fix unnecessary UI redraws without guessing.
18 May 2026, 00:33 UTC

The toggle that redraws the whole screen
You flip a switch in a Jetpack Compose settings screen. The switch animates, but the row beside it does not update—or the entire list flickers and scroll position jumps. In Compose, recomposition should stay local to the composables that read the changed state. When it does not, reading the source code rarely shows why. The missing piece is runtime evidence of what actually redrew.
Android Studio's Layout Inspector connects to a running debuggable app on an emulator or physical device and exposes each Compose node in the layout hierarchy. For Compose debugging, its most useful signal is the recomposition counter: a per-node number that increments whenever that composable recomposes. You can interact with the screen and watch the counters move in real time, which separates UI bugs from unnecessary recomposition without guessing.
What the inspector exposes for Compose nodes
When you select a node in the hierarchy, the inspector shows attributes such as modifier, key, state, and the current recomposition count. The hierarchy mixes Compose nodes with the underlying view layer, so you can see where a ComposeView sits in the window. Live updates mean you do not need to restart the activity after every interaction; you tap, toggle, or scroll in the app and observe the tree from the IDE.
This works alongside Layout Validation, which previews screen sizes, font scales, and color themes before you run the app. Layout Inspector is the runtime companion: it shows what is actually happening on the device, not what the preview assumes.
Worked example: a list row that recomposes on every toggle
Imagine a settings list where each row has a toggle backed by ViewModel state. Flipping one toggle should recompose only that row's toggle and its immediate container. If the whole list recomposes, animations stutter and the list may lose focus.
- Build and run a debuggable build variant. Release builds do not expose full inspector data.
- Deploy to an emulator or attached physical device.
- Open the App Inspection tool window in Android Studio and choose Layout Inspector. Menu paths vary by release, so verify the path for your installed version.
- Connect to the running process and select the row composable in the hierarchy.
- Note the recomposition counter for the row and for unrelated rows.
- Flip the toggle in the app.
- Watch which counters increment.
Expected result: only the toggled row and its direct parent increment. If the counter on every row jumps, state is likely hoisted too high or passed through a composable that reads it unnecessarily. If the target row's counter stays at zero, the composable is not reading the state during composition, or the state holder is not recomposing its callers.
| Symptom | Inspector signal | Likely adjustment |
|---|---|---|
| Whole screen flickers on one toggle | Counter increments on root and unrelated children | Move state lower in the tree or wrap reads in derivedStateOf |
| Target row never updates | Counter stays at zero on the target node | Confirm the composable reads the state; check remember and key placement |
| Counter jumps with unstable input | Numbers climb even without user interaction | Use stable keys for list items; avoid creating new objects in composition |
Limitations to keep in mind
- Requires a debuggable build variant. You cannot attach the full inspector to a release build.
- Runtime inspection adds overhead and can change timing-sensitive behavior. Use it for debugging, not benchmarking.
- Recomposition data depends on stable keys and observable state. Unstable keys make the counter hard to interpret.
- It does not replace crash reporting, network tracing, or the CPU Profiler. Combine it with App Inspection and Profiler for a full picture.
Verify the fix before you move on
After changing state hoisting or keys, repeat the same interaction in Layout Inspector. The counter on the affected node should change by exactly one per user action, and unrelated nodes should stay flat. Compare the inspected hierarchy against your Compose source to confirm that keys and remember blocks match the state you expect. If the numbers still move in unexpected places, the state is likely being read by a parent composable that you did not intend to recompose.
Layout Inspector will not tell you why a recomposition is wrong, but it will show you where it happens. That narrows the search from the whole screen to a few nodes, which is usually enough to find the misplaced state or unstable key.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.