How Recomposition Works

How Recomposition Actually Works

The Compose 234 compiler plugin (Gradle and Compose Compiler) adds two parameters to every @Composable function; javap shows QuantityStepper(int, Function1, Composer, int). The Composer is the cursor into the slot table, where the composition is stored as groups keyed by call site, with everything remember holds; the last int, $changed, is a bit mask through which the caller says which arguments it knows are unchanged. A read of a mutableStateOf during composition is recorded against the running function's restart scope, a write invalidates those scopes, and the next frame re-runs only them:

One tap on the first + button, from state write to skipped children
One tap on the first + button, from state write to skipped children

Layout and drawing follow. Tapping the first + twice logs:

Output of 88
D/BookNestState: CartScreen composed #1
D/BookNestState: CartLine 1 composed #1
D/BookNestState: CartLine 2 composed #1
D/BookNestState: CartLine 3 composed #1
D/BookNestState: CartScreen composed #2
D/BookNestState: CartLine 1 composed #2
D/BookNestState: CartScreen composed #3
D/BookNestState: CartLine 1 composed #3

Only CartScreen and the first line ran again, so read state as low in the tree as you can.