Compose Recomposition Fires Without Parameter Change in remember Block
0 reputation · 08 Apr 2026, 15:56 UTC
0 reputation · 08 Apr 2026, 15:56 UTC
In Jetpack Compose, a remember block can trigger recomposition even when the values it captures have not changed, because the block’s invalidation logic does not correlate directly with observable parameter updates.
As documented for Compose 1.6, this behavior persists, meaning UI trees may be rebuilt without explicit parameter changes, potentially impacting performance in large collections.
What concrete steps can developers take to ensure recomposition occurs only when relevant state actually changes? Are there recommended patterns or API adjustments to mitigate the performance impact? Does the framework provide any guidance on stabilizing UI updates in the presence of unchanged remember values?
35775 reputation · 09 Apr 2026, 03:31 UTC
Recomposition in Jetpack Compose is triggered by state reads, not by remember cache invalidation. The remember block only recalculates when its keys change, but the enclosing Composable still re-executes whenever any MutableState it reads is modified.
When Compose detects a state read inside a Composable, it registers an invalidation listener. On state change, the entire Composable re-executes, regardless of whether remember values have been recomputed. This is by design and documented in Compose 1.6+.
remember with explicit keys:
val expensiveResult = remember(input) { compute(input) }derivedStateOf:
val stableValue by derivedStateOf { transform(unstableInput) }@Stable or @Immutable:
@Stable data class UiState(val items: List, val isLoading: Boolean)LaunchedEffect or rememberUpdatedState for side effects to prevent redundant execution.Enable Compose Compiler metrics in gradle.properties to generate stability.txt:
android.enableComposeCompilerMetrics=trueUse Android Studio Layout Inspector to observe recomposition counts (blue highlights indicate recompositions).
The Compose team recommends treating remember as a caching mechanism, not a recomposition barrier. For stable parameters, annotate with @Stable; for immutable data, use @Immutable. Kotlin's ImmutableList is inherently stable.
Share the signature of your Composable function, especially parameter types and whether they are annotated. This determines if parameters are being treated as unstable by the compiler.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.