
Compose Stability and Recomposition Optimization — @Stable/@Immutable/skippable
What You'll Learn This article explains Compose stability ( @stable , @Immutable, skippable judgment, Compose Compiler Report, and performance optimization). Understanding Stability Compose skips recomposition if arguments haven't changed. Whether skipping is possible depends on the "stability" of the arguments. // ✅ Stable (auto-detected): primitives, String, function types @Composable fun Greeting ( name : String ) { // String = stable → skippable Text ( "Hello, $name" ) } // ❌ Unstable: List, Map and other collections @Composable fun UserList ( users : List < User >) { // List = unstable → recomposed every time LazyColumn { items ( users ) { UserItem ( it ) } } } @Immutable @Immutable data class User ( val id : String , val name : String , val email : String ) // If all properties are val and stable types, add @Immutable // Compose treats this class as guaranteed immutable @stable @Stable class CounterState { var count by mutableIntStateOf ( 0 ) private set fun increment () { count
Continue reading on Dev.to
Opens in a new tab


