Unnecessary Recomposition in Jetpack Compose: Finding the Renders Nobody Asked For
Jetpack Compose promises to redraw only what changed. In practice, that promise depends on the compiler being able to prove that a parameter is "stable": that if it didn't change, Compose can safely skip recomposing the function that receives it. When a parameter isn't stable, Compose can't make that bet, and the conservative choice it falls back to is recomposing anyway, just in case. The result is a UI tree that redraws on every animation frame or every scroll tick, far more than anyone explicitly asked for.
This kind of problem doesn't break the app. The screen looks right, the correct data lands on the correct screen. What degrades is CPU usage during interactions that should be cheap, and it's often only noticed when someone opens the profiler and finds a composable function running hundreds of times during a gesture that should have triggered a single recomposition.
What makes a parameter unstable
Compose classifies every type passed as a parameter to a @Composable function as stable or unstable, and it does this at compile time, not at runtime. A type is stable when the compiler can guarantee that, if its public properties didn't change between two compositions, comparing the old instance to the new one with equals will also behave consistently for that purpose, and that any change to its properties gets notified through snapshot state.
Data classes whose fields are all primitives or String are automatically stable. The problem shows up in structures that are more common than it sounds:
data class ProfileUiState(
val name: String,
val orders: List<Order>
)
List is an interface, and the Compose compiler can't guarantee that any given implementation is immutable: it could be a MutableList that someone calls add on without going through a state mechanism Compose can observe. Since it can't prove it's safe, it marks the entire ProfileUiState as unstable, even though in practice that list's content never changes without the object being recreated. Any @Composable function that receives a ProfileUiState as a parameter loses the ability to have Compose skip it based on structural equality, and ends up recomposing whenever its parent recomposes, regardless of whether the actual value changed.
The other frequent source is lambdas that capture state and get recreated on every recomposition of the parent:
@Composable
fun OrderList(orders: List<Order>, onSelect: (Order) -> Unit) {
LazyColumn {
items(orders) { order ->
OrderCard(order = order, onClick = { onSelect(order) })
}
}
}
The lambda { onSelect(order) } gets created anew every time OrderList recomposes, because it captures order and onSelect from the current scope. A new lambda isn't === to the previous one even if it does exactly the same thing, so OrderCard receives a parameter that counts as changed under the reference comparison Compose uses for functions, and it recomposes even when that card's visual content is identical to the previous frame.
How we found it, not how we assumed it
Before touching any code, we confirmed the problem using two tools, because intuition about what recomposes and what doesn't fails in both directions fairly often.
The first is the Compose compiler's stability report, turned on by adding an option to the compiler in the module:
// build.gradle.kts
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
On compilation, this generates .txt and .csv files listing every class in the module marked as stable, unstable, or "runtime stable" (stable because all of its fields are, even though the class itself has no annotation), along with exactly which field is breaking stability. For ProfileUiState, the report points directly at the orders: List<Order> property as the cause, instead of leaving us to guess which field is the culprit.
The second tool is Layout Inspector's recomposition counter in Android Studio. With the app running, Layout Inspector overlays, on top of the composable tree on screen, how many times each node has recomposed since the view was opened. If OrderCard shows a counter climbing on every scroll even though that specific card isn't visibly changing data, the stability report tells us why, and Layout Inspector confirms it's actually happening, and on exactly which node.
The concrete fixes
For the unstable list, the most direct option is to replace the List interface with a structure Compose can trust is immutable, or to explicitly mark the class as stable when we know, by team convention, that it's never mutated in place:
@Immutable
data class ProfileUiState(
val name: String,
val orders: List<Order>
)
The @Immutable annotation is a promise we make to the compiler, not a guarantee it verifies: we're telling it to trust that this class never changes its properties after construction. If somewhere in the code someone mutates a ProfileUiState instance after creating it — say, by reassigning a var field that should have been a val — the annotation is lying, and Compose may skip recompositions that were actually needed, producing a UI that doesn't update. That's why we only use it when the immutability contract is enforced by the type itself: every field a val, and collections that also aren't mutated in place anywhere in the code that produces them.
For lambdas recreated on every recomposition, the fix is remember with the right keys:
@Composable
fun OrderList(orders: List<Order>, onSelect: (Order) -> Unit) {
LazyColumn {
items(orders, key = { it.id }) { order ->
val onClick = remember(order.id, onSelect) { { onSelect(order) } }
OrderCard(order = order, onClick = onClick)
}
}
}
remember(order.id, onSelect) keeps the same lambda instance across recompositions as long as those two keys don't change, so OrderCard receives a parameter with the same reference identity and Compose can skip its recomposition. Adding key = { it.id } to items fixes a related but separate problem: without that key, Compose identifies each item by its position in the list, so inserting or removing an element in the middle makes every item after it look like it changed identity.
For derived state that gets recalculated on every recomposition even though its result changes less often than its input, we use derivedStateOf instead of a function re-evaluated directly in the composable's body:
val activeOrders by remember(orders) {
derivedStateOf { orders.filter { it.status == OrderStatus.Active } }
}
derivedStateOf only notifies its readers when the lambda's result changes according to equals, not every time orders changes instance. If the order list gets rebuilt on every scroll frame but the subset of active orders stays the same, composables reading activeOrders don't recompose.
What didn't work on the first try
Our first attempt at fixing the OrderCard case was wrapping the whole function in remember, expecting that to prevent the full recomposition:
@Composable
fun OrderCard(order: Order, onClick: () -> Unit) {
remember(order) {
// card content
}
}
This doesn't fix anything: remember memoizes a value computed once, not a block of UI, so wrapping UI inside it doesn't stop the whole composable from running again on the next recomposition if its parent decides it should. We confused value memoization with the actual mechanism behind skipping recomposition, which depends on input parameters being stable and on Compose being able to compare the previous instance with the new one.
What we check before signing off on a screen
Before considering a screen with animations or long lists done, we generate the module's stability report and confirm that the UI state classes passed to frequently recomposed composables are marked stable or @Immutable legitimately, not forced. We open Layout Inspector during an actual scroll or animation and verify that the recomposition counters for nodes that didn't visibly change stay at zero. And we review every lambda passed inside an items call or a loop, because that's where a lambda recreated without remember goes unnoticed most easily.