Share
Embed
Transcript
197 slides
-
Mohit Sarveiya Guide to Improving Compose Performance @heyitsmohit Google Developer
Expert in Kotlin & Android -
Guide to Improving Compose Performance • Recomposition performance • Compiler
Plugin Internals • Compiler Plugin Tests -
Guide to Improving Compose Performance • Recomposition performance • Compiler
Plugin Internals • Compiler Plugin Tests • Experimental features -
Performance Impacts • Initial Composition time • Layout performance •
Recomposition performance -
Stability @Composable fun UsersScreen(modifier: Modifier, users: List<UserModel>) { Column {
users.forEach { model -> User(model) } } } -
Stability @Composable fun UsersScreen(modifier: Modifier, users: List<UserModel>) { Column {
users.forEach { model -> User(model) } } } -
Stability @Composable fun UsersScreen(modifier: Modifier, users: List<UserModel>) { Column {
users.forEach { model -> UserRow(model) } } } @Composable fun UserRow(model: UserModel) -
Stability data class UserModel( var name: String, val friends: List<User>,
val lastLoggedIn: LocalDateTime ) -
Stability Frame 1 Frame 2 Frame 3 Frame 4 Recompose
UsersScreen Recomposition count increase -
What makes a type stable? • Immutability • Observable mutability
(e.g. MutableState) -
Stability data class UserModel( var name: String, val friends: List<User>,
val lastLoggedIn: LocalDateTime ) Mutable -
Stability data class UserModel( var name: String, val friends: List<User>,
val lastLoggedIn: LocalDateTime ) List -
Stability data class UserModel( var name: String, val friends: List<User>,
val lastLoggedIn: LocalDateTime ) Unstable -
Stability Under the Hood • What are the implications of
using unstable types? -
Stability Under the Hood @Composable fun UsersScreen(…) { … }
@Composable fun UserRow() { … } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) Compose Compiler Plugin Transformed IR -
Stability Under the Hood @Composable fun UsersScreen(modifier: Modifier, users: List<UserModel>)
{ Column { users.forEach { model -> UserRow(model) } } } @Composable fun UserRow(model: UserModel) -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { } %composer
= %composer.startRestartGroup() -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { } if
(%changed) { %dirty = %dirty or if (%composer.changedInstance(users)) } %composer = %composer.startRestartGroup() -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { … }
… if (dirty and !%composer.skipping) { items.forEach { model: UserModel -> … } } %composer.endRestartGroup() ?. updateScope { %composer: Composer? -> UsersScreen(users, composer,…) } Recomposition scope -
Unstable data class UserModel( var name: String, val friends: List<User>,
val lastLoggedIn: LocalDateTime ) -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { } if
(%changed and 0b0110 == 0) { %dirty = %dirty or if (%composer.changedInstance(users)) } if (dirty and !%composer.skipping) { … } %composer = %composer.startRestartGroup( <> ) Bit masking -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { } if
(%changed and 0b0110 == 0) { %dirty = %dirty or if (%composer.changedInstance(users)) } if (dirty and !%composer.skipping) { … } %composer = %composer.startRestartGroup( <> ) enum class StabilityBits(val bits: Int) { UNSTABLE(0b100), STABLE(0b000); fun bitsForSlot(slot: Int): Int } -
@Composable fun UsersScreen(users, %composer: Composer?, %changed: Int) { } if
(%changed and 0b0110 == 0) { %dirty = %dirty or if (%composer.changedInstance(users)) } if (dirty and !%composer.skipping) { … } %composer = %composer.startRestartGroup( <> ) Instance Equality for unstable types -
Stable Param class Model(val value: Int = 0) @Composable fun
Test(state: Model) { A(state) } -
Stable Param class Model(val value: Int = 0) @Composable fun
example(state: Model) { A(state) } -
Stable Param @Composable fun example(state, %composer) { %composer = %composer.startRestartGroup()
… if (%changed) { %dirty = %dirty or if (%composer.changed(state)) 0b0100 else 0b0010 } … %composer.endRestartGroup() } -
Stable Param @Composable fun example(state, %composer) { %composer = %composer.startRestartGroup(
<> ) … if (%changed) { %dirty = %dirty or if (%composer.changed(state)) 0b0100 else 0b0010 } … %composer.endRestartGroup() } Equality check -
Unskippable Conditions • Stable parameters have differences from last execution
• If the composer.skipping call returns false -
Unskippable Conditions • Stable parameters have differences from last execution
• If the composer.skipping call returns false • Provided parameters to the function were unstable -
How to Analyze • Stable & Unstable types • Restartable
and Skippable functions -
Compiler Report @Composable fun UsersScreen(…) { … } @Composable fun
UserRow() { … } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) Compose Compiler Plugin Metrics -
Compiler Report Module Metrics Class Stability Transformer Composer Lamba Memoization
Composable Function Body Transformer Composable Param Transformer -
Compiler Report interface ModuleMetrics { fun recordFunction( ... ) fun
recordClass( ... ) fun recordLambda( ... ) fun saveMetricsTo( ... ) } -
Compiler Report class ModuleMetricsImpl(var name: String) : ModuleMetrics { var
skippableComposables = 0 var restartableComposables = 0 var readonlyComposables = 0 var markedStableClasses = 0 var inferredStableClasses = 0 var inferredUnstableClasses = 0 ... } -
Compiler Report Inferred Stable Classes Marked Stable Classes Inferred Unstable
Classes 70 0 Total Classes 61 9 Memoized Lambdas 76 Inferred Uncertain Classes 15 -
Compiler Report kotlinOptions { freeCompilerArgs += [ "-P", “plugin:…kotlin:reportsDestination=“ +
buildDir.absolutePath + "/compose_metrics" ] } -
Compiler Report @Composable restartable fun UsersScreen(…, unstable users: List<UserModel>) @Composable
fun UsersScreen(modifier: Modifier, users: List<UserModel>) -
Stability Under the Hood @Composable fun Profile(modifier: Modifier, user: UserModel)
{ ... } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) -
Stability Under the Hood data class UserModel( var name: String,
val friends: List<User>, val lastLoggedIn: LocalDateTime ) @StabilityInferred(parameters = 0) unstable class User { unstable name: String unstable friends: List<String> unstable lastLoggedIn: LocalDateTime } Class Stability Transformer -
Stability Under the Hood @StabilityInferred(parameters = 0) unstable class User
{ unstable name: String unstable friends: List<String> unstable lastLoggedIn: LocalDateTime } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) Synthesized Annotation -
Stability Under the Hood sealed class Stability { class Certain(…)
: Stability() class Parameter(…) : Stability() class Combined(…) : Stability() class Runtime(…) : Stability() class Unknown(…) : Stability() … } Internal to Compiler -
Stability Under the Hood sealed class Stability { class Certain(…)
: Stability() class Parameter(…) : Stability() class Combined(…) : Stability() class Runtime(…) : Stability() class Unknown(…) : Stability() … } -
Stability Under the Hood sealed class Stability { class Certain(…)
: Stability() class Parameter(…) : Stability() class Combined(…) : Stability() class Runtime(…) : Stability() class Unknown(…) : Stability() … } -
Stability Under the Hood unstable class User { unstable name:
String unstable friends: List<String> unstable lastLoggedIn: LocalDateTime } Stability.Certain(false) -
Stability Under the Hood unstable class User { unstable name:
String unstable friends: List<String> unstable lastLoggedIn: LocalDateTime } Stability.Runtime -
Compiler Report Inferred Stable Classes Marked Stable Classes Inferred Unstable
Classes 70 0 Total Classes 61 9 Memoized Lambdas 76 Inferred Uncertain Classes 15 -
Stability Under the Hood class StabilityInferencer( ... ) { fun
stabilityOf( declaration: IrClass ): Stability { ... } } What are the rules for stability? -
Stability Under the Hood fun stabilityOf( declaration: IrClass ): Stability
{ val fqName = declaration.fqNameWhenAvailable if (KnownStableConstructs.stableTypes.contains(fqName)) { stability = Stability.Stable } } -
Stability Under the Hood fun stabilityOf( declaration: IrClass ): Stability
{ val fqName = declaration.fqNameWhenAvailable if (KnownStableConstructs.stableTypes.contains(fqName)) { stability = Stability.Stable } } Known Stable Types -
Known Stable Types • Primitive types • Pair, Triple •
Comparator, ClosedRange, • Result -
Stability Under the Hood message User name: String location: String
lastLoggedIn: LocalDataTime } @Composable fun Profile(modifier: Modifier, user: User) { ... } Protobuff -
Stability Under the Hood @Composable fun Profile(modifier: Modifier, user: User)
{ ... } message User name: String location: String lastLoggedIn: LocalDataTime } import com.google.protobuf.GeneratedMessageLite -
Stability Under the Hood @Composable restartable fun Profile(modifier: Modifier, unstable
user: User) { ... } message User name: String location: String lastLoggedIn: LocalDataTime } import com.google.protobuf.GeneratedMessageLite -
Stability Under the Hood fun IrClass.isProtobufType(): Boolean { val directParentClassName
= superTypes.lastOrNull { … }.fqNameWhenAvailable return directParentClassName == "com.google.protobuf.GeneratedMessageLite" || directParentClassName == "com.google.protobuf.GeneratedMessage" } -
Stability Under the Hood fun IrClass.isProtobufType(): Boolean { val directParentClassName
= superTypes.lastOrNull { … }.fqNameWhenAvailable return directParentClassName == "com.google.protobuf.GeneratedMessageLite" || directParentClassName == "com.google.protobuf.GeneratedMessage" } -
Stability Under the Hood fun stabilityOf( declaration: IrClass ): Stability
{ ... if (declaration.isInterface) { return Stability.Unknown(declaration) } } -
Stability Under the Hood class A class B class Foo(val
pair: Pair<A, B>) -
Stability Under the Hood // Stability.Runtime class A class B
class Foo(val pair: Pair<A, B>) -
Stable Markers unstable class User { unstable name: String unstable
friends: List<String> unstable lastLoggedIn: LocalDateTime } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) -
Stability Markers fun stabilityOf( declaration: IrClass ): Stability { if
(declaration.hasStableMarkedDescendant()) { return Stability.Stable } … } -
Stability Markers fun stabilityOf( declaration: IrClass ): Stability { if
(declaration.hasStableMarkedDescendant()) { return Stability.Stable } … } Stability Marker Check -
Stability Markers @Stable data class UserModel( val name: String, val
friends: ImmutableList<User>, val lastLoggedIn: LocalDateTime ) -
Stability Markers @StabilityInferred(parameters = 3) stable class UserModel { stable
name: String stable friends: ImmutableList<String> stable lastLoggedIn: LocalDateTime } -
Stability Markers @Composable restartable fun Profile(…, stable user: UserModel) @Composable
fun Profile(modifier: Modifier, user: UserModel) { ... } -
Stability Markers @Composable restartable skippable fun Profile(…, stable user: UserModel)
@Composable fun Profile(modifier: Modifier, user: UserModel) { ... } -
Stability Under the Hood data class UserModel( var name: String,
val friends: List<User>, val lastLoggedIn: LocalDateTime ) @StabilityInferred(parameters = 0) unstable class User { unstable name: String unstable friends: List<String> unstable lastLoggedIn: LocalDateTime } Stability Inferencer -
Testing Stability data class UserModel( var name: String, val friends:
List<User>, val lastLoggedIn: LocalDateTime ) Compose Compiler Plugin @Composable fun Profile( ... ) IR -
Testing Stability data class UserModel( var name: String, val friends:
List<User>, val lastLoggedIn: LocalDateTime ) @Composable fun Profile( ... ) K1Compiler Facade K2Compiler Facade -
Testing Stability val irModule = compileToIr(source) val stabilityInferencer = StabilityInferencer(irModule.descriptor)
val classStability = stabilityInferencer.stabilityOf(irClass) // Stability.Stable -
Testing Stability val irModule = compileToIr(source) val stabilityInferencer = StabilityInferencer(irModule.descriptor)
val classStability = stabilityInferencer.stabilityOf(irClass) // Stability.Stable -
Testing Stability val irModule = compileToIr(source) val stabilityInferencer = StabilityInferencer(irModule.descriptor)
val classStability = stabilityInferencer.stabilityOf(irClass) // Stability.Stable -
Testing Stability @Test fun testSingleValPrimitiveIsStable() = assertStability( "class Foo(val value:
Int)", "Stable" ) Utility converts to IR -
Strategies • Use stable types • Use @Stable or @Immutable
markers • Mark NonRestartableComposable for “root” -
Non Restartable Composable @Composable fun example(model: Unstable) { remember(model) {
1 } } restartable fun example(unstable model: Unstable) -
Non Restartable Composable @Composable fun example(model: Unstable, %composer: Composer?, %changed:
Int) { %composer.startRestartGroup() val tmp0_group = %composer.cache(%composer.changed(model)) { 1 } ... %composer.endRestartGroup().updateScope({…}) } -
Non Restartable Composable @Composable fun example(model: Unstable, %composer: Composer?, %changed:
Int) { %composer.startRestartGroup() val tmp0_group = %composer.cache(%composer.changed(model)) { 1 } ... %composer.endRestartGroup().updateScope({…}) } -
Non Restartable Composable @Composable @NonRestartableComposable fun example(model: Unstable) { remember(model)
{ 1 } } fun example(unstable model: Unstable) Not restartable nor skippable -
Non Restartable Composable @Composable fun example(model: Unstable, %composer: Composer?, %changed:
Int) { val tmp0_group = %composer.cache(%composer.changedInstance(model)) { 1 } ... } No restart group created -
Without Strong Skipping @Composable fun Profile(modifier: Modifier, user: User) {
... } restartable fun Profile( stable modifier: Modifier? = @static Companion unstable user: User ) Only restartable -
With Strong Skipping @Composable fun Profile(modifier: Modifier, user: User) {
... } restartable skippable fun Profile( stable modifier: Modifier? = @static Companion unstable user: User ) All restartable functions are skippable -
Strong Skipping • Unstable —> Instance Equality • Stable —>
Object Equality -
@Composable fun Profile(user, %composer: Composer?, %changed: Int) { } if
(%changed and 0b0110 == 0) { %dirty = %dirty or if (%composer.changedInstance(users)) } if (dirty and !%composer.skipping) { … } %composer = %composer.startRestartGroup( <> ) enum class StabilityBits(val bits: Int) { UNSTABLE(0b100), STABLE(0b000); fun bitsForSlot(slot: Int): Int } -
Strong Skipping Lambdas class Unstable(var value: Int = 0) @Composable
fun example() { val unstableObject = Unstable(0) val lambda = { unstableObject } } -
Strong Skipping Lambdas @Composable fun example(%composer: Composer?, %changed: Int) {
… if (%changed) { val foo = Unstable(0) val lambda = %composer.cache( %composer.changedInstance(unstableObject)) { { unstableObject } } … } Memoize Lambda -
Strong Skipping Lambdas (Opt out) class Unstable(var value: Int =
0) @Composable fun example() { val unstableObject = Unstable(0) val lambda = @DontMemoize { unstableObject } } -
Strong Skipping Lambdas (Opt out) @Composable fun example(%composer: Composer?, %changed:
Int) { ... if (%changed) { val unstableObject = Unstable(0) val lambda = { { unstableObject } } } ... } Not Memoized -
@Composable @NonRestartableComposable fun example(model, %composer: Composer?) { } %composer =
%composer.startReplaceGroup() gets a replace group placed around the body -
@Composable @NonRestartableComposable fun example(model, %composer: Composer?) { } %composer =
%composer.startReplaceGroup() if (%changed) { %dirty = %dirty or if (%composer.changedInstance(…)) } Never calls `$composer.changed( ... )` with its parameters -
@Composable @NonRestartableComposable fun example(model, %composer: Composer?) { } %composer =
%composer.startReplaceGroup() if (show) { %composer.startMoveableGroup() … %composer.endMovableGroup() } Proper groups around control flow -
@Composable @NonRestartableComposable fun example(model, %composer: Composer?) { } %composer =
%composer.startReplaceGroup() if (show) { %composer.startMoveableGroup() … %composer.endMovableGroup() } Not necessary -
@Composable @NonRestartableComposable fun example(model, %composer: Composer?) { … } Never
omit if (show) { %composer.startMoveableGroup() … %composer = %composer.endMovableGroup() } -
Guide to Improving Compose Performance Performance Tip: Reduce recompositions by
reusing moveContentOf -
moveableContentOf val content = remember { content } if (showVertical)
{ Column { content() } } else { Row { content() } } -
moveableContentOf val content = remember { content } if (portrait)
{ Column { content() } } else { Row { content() } } -
moveableContentOf val content = remember { moveableContentOf(content) } if (showVertical)
{ Column { content() } } else { Row { content() } } -
Inside Compiler Plugin Compose Compiler Plugin Test Recompositions val content
= remember { content } if (showVertical) { Column { content() } } else { Row { content() } } -
Inside Compiler Plugin interface CompositionTestScope : CoroutineScope { fun compose(block:
@Composable () -> Unit) fun revalidate() ... } -
Inside Compiler Plugin val content = movableContentOf { val privateState
= remember { mutableStateOf(0) } Text("Heading") Text("Content") } -
Inside Compiler Plugin var portrait by mutableStateOf(false) val content =
movableContentOf { val privateState = remember { mutableStateOf(0) } Text("Heading") Text(“Content") } -
Inside Compiler Plugin @Composable fun example() { if (portrait) {
Column { content() } } else { Row { content() } } } -
Inside Compiler Plugin var lastPrivateState: State<Int> = mutableStateOf(0) var portrait
by mutableStateOf(false) val content = movableContentOf { val privateState = remember { mutableStateOf(0) } lastPrivateState = privateState Text("Heading") Text(“Content") } -
Inside Compiler Plugin interface CompositionTestScope : CoroutineScope { ... fun
compose(block: @Composable () -> Unit) fun revalidate() ... } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState Content()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState example()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState example()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState example()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState example()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin compose { val firstPrivateState = lastPrivateState example()
portrait = true Snapshot.sendApplyNotifications() revalidate() assertSame(firstPrivateState, lastPrivateState) } -
Inside Compiler Plugin var portrait by mutableStateOf(false) val content =
movableContentOf { val privateState = remember { mutableStateOf(0) } lastPrivateState = privateState Text("Heading") Text(“Content") } -
moveableContentOf • Nodes are preserved. • State is remembered as
groups are moved. -
Guide to Improving Compose Performance Performance Tip: Use derivedStateOf for
frequently changing state -
derivedStateOf @Composable fun Profile() { var shouldShowFab = remember(lazyListState.firstVisibleItemIndex) {
lazyListState.firstVisibleItemIndex > 10 } if(shouldShowFab){ /* Display the floating action button */ } } -
derivedStateOf @Composable fun Profile() { var shouldShowFab = remember(lazyListState.firstVisibleItemIndex) {
lazyListState.firstVisibleItemIndex > 10 } if(shouldShowFab){ /* Display the floating action button */ } } -
derivedStateOf @Composable fun Profile() { var shouldShowFab = remember(lazyListState.firstVisibleItemIndex) {
lazyListState.firstVisibleItemIndex > 10 } if(shouldShowFab){ /* Display the floating action button */ } } -
derivedStateOf Profile Frame 1 Frame 2 Frame 3 Frame 4
Recompose Recomposition count increase Pro .. Pro. Pro. Pro. Pro. Pro. Pro. Pro. Pro. -
derivedStateOf @Composable fun Profile() { var shouldShowFab = remember(lazyListState.firstVisibleItemIndex) {
lazyListState.firstVisibleItemIndex > 10 } if(shouldShowFab){ /* Display the floating action button */ } } Value changes very frequently -
derivedStateOf @Composable fun Profile() { val shouldShowFab = remember(lazyListState.firstVisibleItemIndex){ derivedStateOf
{ lazyListState.firstVisibleItemIndex > 10 } } … } -
derivedStateOf fun <T> derivedStateOf( policy: SnapshotMutationPolicy<T>, calculation: () -> T,
): State<T> How do we compare previous values? -
Inside Compiler Plugin @Composable fun UsersScreen(…) { … } @Composable
fun UserRow() { … } data class UserModel( var name: String, val friends: List<User>, val lastLoggedIn: LocalDateTime ) Compose Compiler Plugin Test Snapshot changes -
Inside Compiler Plugin class SnapshotStateObserver(…) { fun observeReads(…) fun start()
fun stop() fun notifyChanges() … } -
Inside Compiler Plugin class SnapshotStateObserver(…) { fun observeReads(…) fun start()
fun stop() fun notifyChanges() … } -
Inside Compiler Plugin fun runSimpleTest( block: (…) -> Unit )
{ val stateObserver = SnapshotStateObserver { it() } try { stateObserver.start() block(stateObserver,…) Snapshot.sendApplyNotifications() } finally { stateObserver.stop() } } -
Inside Compiler Plugin fun runSimpleTest( block: (…) -> Unit )
{ val stateObserver = SnapshotStateObserver { it() } try { stateObserver.start() block(stateObserver,…) Snapshot.sendApplyNotifications() } finally { stateObserver.stop() } } -
Referential Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) val derivedState = derivedStateOf(referentialEqualityPolicy()) { state.value } } -
Referential Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) val derivedState = derivedStateOf(referentialEqualityPolicy()) { state.value } } -
Referential Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) val derivedState = derivedStateOf(referentialEqualityPolicy()) { state.value } } -
Referential Equality Policy runSimpleTest { stateObserver, _ -> … var
changes = 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } } -
Referential Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) var changes = 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } state.value = mutableListOf(1) } Update State -
Referential Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) val derivedState = derivedStateOf(referentialEqualityPolicy()) { state.value } state.value = mutableListOf(1) } State will observe read due to ref check -
Referential Equality Policy runSimpleTest { stateObserver, _ -> var changes
= 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } state.value = mutableListOf(1) assertEquals(1, changes) } Changes is updated -
Referential Equality Policy runSimpleTest { stateObserver, _ -> var changes
= 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } state.value = mutableListOf(1) assertEquals(1, changes) } -
Structural Equality Policy runSimpleTest { stateObserver, _ -> val state
= mutableStateOf(mutableListOf(1)) val derivedState = derivedStateOf(structureEqualityPolicy()) { state.value } } -
Structural Equality Policy runSimpleTest { stateObserver, _ -> var changes
= 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } state.value = mutableListOf(1) assertEquals(0, changes) // changes = 0 } Value is not emitted by derived state -
Structural Equality Policy runSimpleTest { stateObserver, _ -> var changes
= 0 stateObserver.observeReads(…, { changes ++ }) { derivedState.value } state.value = mutableListOf(1) assertEquals(0, changes) // changes = 0 } -
Guide to Improving Compose Performance • Recomposition performance • Compiler
Plugin Internals • Compiler Plugin Tests • Experimental features