Deriving derived state: derivedStateOf explained
summary
derivedStateOf is a custom Compose state that reduces invalidations and caches per-snapshot results so expensive or lazily-used calculations (example: sorting a large list for LazyColumn layout and draw) run far less often. implementation stores dependency record IDs, snapshot IDs and write counts, hashes record IDs to detect changes, and handles nested derived states. avoid using it for cheap calculations or when outputs change as often as inputs, and ensure the lambda only reads snapshot-backed state and use rememberUpdatedState when capturing external values.
AI-written summary · about
chapters (10)
- 0:00Introduction to derivedStateOf
- 1:08When to use derivedStateOf
- 3:57Lazy calculations with derivedStateOf
- 6:49Anti-patterns with derivedStateOf
- 8:53Invalidation in derivedStateOf
- 16:20Invalidation tracking phases
- 21:06Caching in derivedStateOf
- 23:15Snapshot-based caching
- 35:17Complexity of derivedStateOf
- 37:25Summary and best practices
related talks
36mUnderstanding Recomposition Performance Pitfalls
52mState management beyond the libraries
44mState in Jetpack Compose
28mCompose at Scale: Stop Unnecessary Recomposition
40mCompose Without Flow: Unidirectional State with Snapshots and Coroutines
38mWhat does Recomposition mean to your app?
49mWhat does Recomposition mean to your app?
38mEssential concepts to know when learning Declarative UI
