Learn how Jetpack Compose recomposition, parameter stability and strong skipping mode decide when composables skip, and how to fix extra recompositions. About 25 minutes.
Why it matters
A composable that recomposes on every frame or keystroke wastes CPU on the main thread. Knowing why Compose skips or re-runs a function lets you fix jank instead of guessing.
Strong skipping mode is on by default from Kotlin 2.0.20 with the Compose compiler Gradle plugin (org.jetbrains.kotlin.plugin.compose). Much older advice about stability (wrap every lambda in remember, convert every List to ImmutableList) no longer applies, and some of it now costs performance.
Senior Android interviews often ask you to explain stability, @Stable vs @Immutable, and why a child recomposed. You need the real comparison rules, not folklore.
Compose compiler reports (reportsDestination, metricsDestination in the composeCompiler Gradle block) and Layout Inspector recomposition counts show what actually happens in your code.
The simple explanation
A composable is a worker on an assembly line; recomposition is the foreman asking it to redo its part.
Before calling the worker again, the foreman compares the new parts (parameters) with last time's parts.
A stable part can be compared by contents (equals): two identical boxes count as "the same".
An unstable part is compared by identity (===) under strong skipping: only the very same box counts as "the same".
If every part matches, the worker is skipped and its old output is kept.
What is recomposition in Jetpack Compose? It is Compose calling your composable functions again when the state they read changes, so the UI matches the new data. Compose does not redraw everything: it re-runs only the restart scopes that read the changed state, and during that pass it can skip child composables whose parameters have not changed.
Restartable and skippable. Most composables that return Unit are restartable: Compose can re-run just that function when state it read changes. A skippable composable can be skipped when its parent recomposes and all its arguments compare equal to the previous ones. With strong skipping (the default from Kotlin 2.0.20), every restartable composable is also skippable, even if some parameters are unstable.
Stability. The compiler decides whether each type is stable:
Type
Stability
Comparison under strong skipping
Int, String, Float, other primitives
Stable
equals
Class with only val properties of stable types, compiled with the Compose compiler
Stable (inferred)
equals
List<T>, Set<T>, Map<K, V> (interfaces)
Unstable
=== (same instance)
Class from a module without the Compose compiler, or with a var property
Unstable
===
State<T>, MutableState<T>, function types
Stable
equals
ImmutableList<T> from kotlinx.collections.immutable
Stable
equals, element by element
So under strong skipping, a List parameter skips when the parent passes the same instance. The common cause of extra recomposition is a parent that allocates a new instance every time it runs, for example users.filter { ... } in the composable body. The fix Google now recommends is to keep the instance stable (do the work in the ViewModel, or remember(key) { ... }), not to force structural comparison everywhere.
Lambdas. With strong skipping, every lambda inside a composable is wrapped in remember automatically, keyed on what it captures. You rarely need remember { { ... } } by hand.
@Stable and @Immutable. Both make the compiler treat a type as stable, so it is compared with equals. @Immutable promises nothing observable ever changes after construction. @Stable allows mutation as long as it happens through snapshot state, so Compose is notified. Annotations override inference (like !!), so a wrong annotation can make Compose skip when the data really changed. For classes you cannot annotate, list them in a stability configuration file passed with stabilityConfigurationFiles in the composeCompiler block.
Does the child run again?
Stable parameters are compared by value, unstable ones by instance. One mismatch is enough to make the child run again.
Notes
Strong skipping is the default from Kotlin 2.0.20. Unstable parameters are compared with ===, stable parameters with equals. All restartable composables become skippable.
Before strong skipping, a composable with any unstable parameter was not skippable at all: it re-ran every time its parent recomposed.
A class with only val properties of stable types, in a module built with the Compose compiler, is inferred stable. It needs no annotation.
Classes from a module without the Compose compiler (often a pure Kotlin data module) are unstable. Options: a stability configuration file, @Immutable (which needs a Compose runtime dependency in that module), or mapping to UI models.
List, Set and Map are unstable because they are interfaces and the implementation may be mutable. Under strong skipping that is usually fine as long as you pass the same instance.
Be careful replacing List with ImmutableList or annotating collection-holding models: that makes Compose compare every element with equals, which can cost more than a recomposition in big lists. Prefer preserving the instance.
Lambdas are remembered automatically under strong skipping. Use @DontMemoize to opt one out and @NonSkippableComposable to make a function restartable but never skipped.
mutableStateOf(mutableListOf()) plus .add() does not trigger recomposition: the State was never written. Use mutableStateListOf() or assign a new list (items = items + item).
derivedStateOf is for state that changes more often than the result you need, such as listState.firstVisibleItemIndex > 0. For "recompute when this key changes", remember(key) { ... } is the right tool.
Verify with Layout Inspector (recomposition and skip counts) and with the compiler's composables.txt report, which marks each function restartable, skippable and each parameter stable or unstable.
Code example
A search screen filters a list. The first version allocates a new List every time the parent recomposes, so the child cannot skip. The second keeps the same instance until the inputs change.
import androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.lazy.LazyColumnimport androidx.compose.foundation.lazy.itemsimport androidx.compose.material3.Buttonimport androidx.compose.material3.Textimport androidx.compose.material3.TextFieldimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue// Inferred stable: only val properties of stable typesdata class User(val id: Long, val name: String)@Composablefun UserList(users: List<User>) { // List is unstable: compared with === LazyColumn { items(users, key = { it.id }) { user -> Text(user.name) } }}// BAD: filter runs in the body, so every recomposition passes a new List@Composablefun SearchScreenBad(allUsers: List<User>) { var query by remember { mutableStateOf("") } var clicks by remember { mutableIntStateOf(0) } Column { TextField(value = query, onValueChange = { query = it }) Button(onClick = { clicks++ }) { Text("Click") } Text("Clicks: $clicks") // read here, so a click recomposes this whole scope... UserList(allUsers.filter { it.name.contains(query, ignoreCase = true) }) // ...and UserList too }}// GOOD: the filtered list is cached until allUsers or query changes@Composablefun SearchScreenGood(allUsers: List<User>) { var query by remember { mutableStateOf("") } var clicks by remember { mutableIntStateOf(0) } val filtered = remember(allUsers, query) { allUsers.filter { it.name.contains(query, ignoreCase = true) } } Column { TextField(value = query, onValueChange = { query = it }) Button(onClick = { clicks++ }) { Text("Click") } Text("Clicks: $clicks") UserList(filtered) // same instance when only clicks changed -> skipped }}
User needs no annotation: the compiler infers it stable, so it is compared with equals.
In SearchScreenBad, any recomposition of the screen (here, clicks changing) creates a new List, so UserList fails the === check and re-runs.
In SearchScreenGood, remember(allUsers, query) returns the same instance until an input changes, so UserList is skipped. In a real app the ViewModel usually does the filtering and exposes the result in StateFlow, which also preserves the instance between emissions.
The onValueChange lambda is remembered automatically by strong skipping; no manual remember needed.
Run the idea in plain Kotlin
The skip check is modelled as a function: stable parameters compare with ==, unstable ones with ===.
data class User(val id: Long, val name: String)
// Strong skipping rule: stable -> equals, unstable -> same instance
fun skips(previous: Any, next: Any, stable: Boolean): Boolean =
if (stable) previous == next else previous === next
fun main() {
val all = listOf(User(1, "Alice"), User(2, "Bob"), User(3, "Ann"))
// Parent filters in its body on every recomposition
val first = all.filter { it.name.startsWith("A") }
val second = all.filter { it.name.startsWith("A") }
println("Same contents: " + (first == second))
println("List param, new instance each time -> skip? " + skips(first, second, stable = false))
// Parent caches the result (remember / ViewModel)
val cache = HashMap<String, List<User>>()
val a = cache.getOrPut("A") { all.filter { it.name.startsWith("A") } }
val b = cache.getOrPut("A") { all.filter { it.name.startsWith("A") } }
println("List param, cached instance -> skip? " + skips(a, b, stable = false))
// Stable data class: new but equal instance still skips
println("User param, equal copy -> skip? " + skips(User(1, "Alice"), User(1, "Alice"), stable = true))
println("User param, changed name -> skip? " + skips(User(1, "Alice"), User(1, "Alicia"), stable = true))
}
Expected output:
Same contents: true
List param, new instance each time -> skip? false
List param, cached instance -> skip? true
User param, equal copy -> skip? true
User param, changed name -> skip? false
In production
Result list recomposed on every unrelated state change
A search screen kept a "selected filter chip" state and the result list in the same composable. Layout Inspector showed the result list recomposing every time a chip was toggled, even when the results did not change.
The composable body called results.sortedBy { it.title } and passed the new list down. Each recomposition produced a new List instance, so the child failed the === check.
A teammate's first attempt was to convert the list to ImmutableList, which made the child compare every element with equals on each pass. It skipped, but the comparison itself showed up in traces for long lists.
The fix
Sorting moved into the ViewModel, which exposes the sorted list in a StateFlow. The same instance is emitted until the data changes, so the child skips under strong skipping without any annotation.
The team checked the result in Layout Inspector: the list's recomposition count stopped increasing when chips were toggled.
They kept the parameter as a plain List and documented the rule: preserve instances first, reach for ImmutableList only when a benchmark shows it helps.
List mutation invisible to Compose
Adding an item to a cart did not update the UI.
The code used val cart = remember { mutableStateOf(mutableListOf<Item>()) } and called cart.value.add(newItem).
The MutableState was never written, so the snapshot system recorded no change and nothing was invalidated.
The fix
Replaced it with mutableStateListOf<Item>(), a SnapshotStateList whose reads are tracked and whose writes (add, remove) invalidate the readers.
Where the list came from a ViewModel, the ViewModel emitted a new immutable list (items + newItem) in its StateFlow instead.
A unit test collects snapshotFlow { cart.size } and checks that a new size is emitted after add.
Common mistakes
Allocating collections in the composable body.list.filter, map or sortedBy in the body produce a new instance on each recomposition, so a child taking that list never skips. Move the work to the ViewModel or remember(key) { ... }.
Using ImmutableList everywhere as a reflex. It makes Compose compare element by element with equals on every recomposition. Prefer keeping the same instance; measure before forcing structural comparison.
Annotating classes the compiler already infers as stable. A data class with val properties of stable types in a Compose module is already stable. Annotate only types the compiler cannot infer, such as classes from non-Compose modules, and only when their equals is cheap.
Lying with @Immutable. Putting @Immutable on a class with a var or a mutable list lets Compose skip a child whose data really changed, which shows stale UI.
Mutating a list inside mutableStateOf with .add(). The State is not written, so Compose is not notified. Use mutableStateListOf() or assign a new list.
Hand-wrapping every lambda in remember. Strong skipping already memoizes lambdas keyed on their captures. Extra remember calls add noise.
Chasing recomposition counts alone. Skipping has a cost too (parameters are stored and compared). Focus on light composables and deferred reads of fast-changing state, and confirm with benchmarks.
Interview questions
Answer out loud first. Then reveal the answer and compare it at each depth.
“What is recomposition in Jetpack Compose, and how does Compose decide to skip a composable?”
“What is the difference between @Stable and @Immutable?”
“A LazyColumn row recomposes when unrelated state changes. How do you find and fix it?”
“What does strong skipping mode change, and what can go wrong?”
Quiz
With strong skipping enabled, how does Compose compare an unstable List<User> parameter?
data class User(val name: String, val age: Int) is declared in a module built with the Compose compiler. What do you need to make it stable?
You call mutableStateOf(mutableListOf<Item>()) and then state.value.add(newItem). What happens?
How do you tell the Compose compiler to treat a class from a third-party library as stable?
0 of 4 answered
Mini task
Find and fix one unnecessary recomposition (20 min)
Pick a screen. Choose a screen with a list and at least one other piece of state (a filter, a toggle, a counter).
Measure. Run the app, open Layout Inspector, enable recomposition counts, and change the unrelated state a few times. Note which composables' counts go up.
Generate reports. Add to the module's build.gradle.kts:
Run ./gradlew :app:assembleRelease and open app/build/compose_compiler/app_release-composables.txt (the exact file name depends on module and variant).
Find the cause. For the composable that recomposed, check whether a parameter is unstable and whether the parent creates a new instance each time (a filter, map or sortedBy in the body, or a mapping in the collector).
Fix it. Move the work into the ViewModel or remember(key) { ... } so the same instance is passed until the data changes. Only if the type comes from a non-Compose module and is re-created with equal values, add it to a stability configuration file.
Re-measure. Repeat step 2.
Done condition: in Layout Inspector, the list composable's recomposition count no longer rises when you change the unrelated state, and the app still updates the list when the data really changes.