Opening the shutter on snapshots
summary
Jetpack Compose’s snapshot system is a tiny runtime library (not compiler magic) that implements MVCC with a monotonic ID counter and per-snapshot invalid ID sets, storing history as per-state linked lists of records and using ThreadLocal context to pick the visible record. Writes create per-snapshot records, apply moves IDs into the parent and removes invalid marks, and conflicts call a merge records policy. Examples include mutable state implementation and a working GitHub demo that diffs a mutable snapshot to drive animations.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:16Why snapshots are needed
- 3:50ACID properties explained
- 5:37How snapshots work technically
- 7:40Records and state objects
- 10:07Snapshot operations
- 13:00Snapshot IDs as a clock
- 16:31Applying and advancing snapshots
- 19:24Nested snapshots example
- 21:40Mutable state implementation
- 26:13Conflict resolution policies
- 28:00Custom snapshot-aware state
- 31:53Diffing state for animations
- 35:07Adding durability to snapshots
- 38:35Key takeaways and resources
related talks
28mA Hitchhiker's Guide to Compose Compiler: Composers, Compiler Plugins, and Snapshots
40mJetpack Compose Mechanisms
40mCompose Without Flow: Unidirectional State with Snapshots and Coroutines
42mJetpack Compose: Art of the State
45mMastering Recomposition: Optimizing State Changes for Efficient UI
31mDesigning Media Friendly Jetpack Compose Components
01h 12mJetpack Compose over inheritance
40mThe Compose Runtime, Demystified
