Avoid Recomposition Via Remember
A composable's body re-runs on every recomposition. Anything allocated or computed at the top level of the body — a parser, a Regex, a sorted list, a formatted string — runs every recomposition unless wrapped in `remembe…
$ prime install @android-compose/rule-avoid-recomposition-via-remember Projection
Always in _index.xml · the agent never has to ask for this.
AvoidRecompositionViaRemember [rule] v0.1.0
A composable's body re-runs on every recomposition. Anything allocated or computed at the top level of the body — a parser, a Regex, a sorted list, a formatted string — runs every recomposition unless wrapped in remember. Pure observable derivations should use derivedStateOf, which only emits when its result changes (skipping recompositions whose inputs change but whose output does not). Remember keys must be the inputs that, when changed, require recomputation.
Loaded when retrieval picks the atom as adjacent / supporting.
AvoidRecompositionViaRemember [rule] v0.1.0
A composable's body re-runs on every recomposition. Anything allocated or computed at the top level of the body — a parser, a Regex, a sorted list, a formatted string — runs every recomposition unless wrapped in remember. Pure observable derivations should use derivedStateOf, which only emits when its result changes (skipping recompositions whose inputs change but whose output does not). Remember keys must be the inputs that, when changed, require recomputation.
Checks
- Allocations or expensive computations are wrapped:
val parser = remember { JsonParser(...) }. - Derived state from snapshot reads uses
remember { derivedStateOf { ... } }so consumers only recompose when the derived value changes. - Remember keys list every input the computation depends on:
remember(query, locale) { fuse(query, locale) }. - Functions defined inside a composable body that capture state are wrapped in
rememberto keep referential equality stable across recompositions.
Label
Cache expensive values across recompositions with remember / derivedStateOf
Loaded when retrieval picks the atom as a focal / direct hit.
AvoidRecompositionViaRemember [rule] v0.1.0
A composable's body re-runs on every recomposition. Anything allocated or computed at the top level of the body — a parser, a Regex, a sorted list, a formatted string — runs every recomposition unless wrapped in remember. Pure observable derivations should use derivedStateOf, which only emits when its result changes (skipping recompositions whose inputs change but whose output does not). Remember keys must be the inputs that, when changed, require recomputation.
Checks
- Allocations or expensive computations are wrapped:
val parser = remember { JsonParser(...) }. - Derived state from snapshot reads uses
remember { derivedStateOf { ... } }so consumers only recompose when the derived value changes. - Remember keys list every input the computation depends on:
remember(query, locale) { fuse(query, locale) }. - Functions defined inside a composable body that capture state are wrapped in
rememberto keep referential equality stable across recompositions.
Label
Cache expensive values across recompositions with remember / derivedStateOf
Label
Cache expensive values across recompositions with remember / derivedStateOf
Source
prime-system/examples/android-compose/primes/compiled/@android-compose/rule-avoid-recomposition-via-remember/atom.yaml