Why are Function Types Stable in Jetpack Compose?
Unpacking the "Observability Gap" and why () -> Unit is stable even when its data is not. Why does a lambda that returns unstable data still count as “stable” in Compose? The answer reveals how recomposition actually works under the hood. TL;DR: In Jetpack Compose, function types (lambdas) are considered stable because their identity is the only observable signal Compose can use during recomposition. However, stability does not guarantee reactivity — state must be read inside composables, not hidden inside lambdas. To maintain performance, you must manually manage identity using remember . The Mental Model: Compose Recomposition vs. Execution Phase To understand function stability, you must distinguish between the two distinct timings in a Composable’s lifecycle: Recomposition Phase: Compose compares inputs to decide if it can skip a function. If inputs (like a lambda) have the same identity , Compose skips the work. E...