Android & Jetpack Compose (50 Qs)•Part 2: Compose Internals, Persistence, DI & Background Work (11 - 24)
How does Recomposition work internally in Jetpack Compose?
senior LevelCode ExampleDocker & Containers
In Simple Words: Recomposition is the process of re-running composable functions when state inputs change:
- Slot Table: Compose stores composable hierarchy and remembered state in an internal continuous in-memory array called a Slot Table.
- Positional Memoization: Compose identifies UI elements by their call-site execution position in the Slot Table.
- Smart Recomposition (Skipping): If a composable function is marked
@Stableand its input parameters have not changed (equals() == true), Compose skips execution entirely, saving massive CPU time!
text
Compose Internal Pipeline:
State Change ──► Snapshot System Notified
│
(Smart Skipping Check)
│
Recompose Only Changed Functions
│
Update In-Memory Slot Table
│
Apply Changes to Android Layout / Drawing