What problem does it solve?
Jetpack Compose can trigger expensive recompositions when high-frequency data streams are read directly inside composables, causing UI jank and unstable rendering at sensor/telemetry rates.
Core Features & Use Cases
- Granular State Management: Avoid collecting whole telemetry frames in a single composable by splitting StateFlow into per-metric StateFlows and applying
distinctUntilChanged() to prevent unnecessary recomposition.
- Derived UI Values: Use
derivedStateOf to recompute and re-render only when the derived result changes, not on every upstream update.
- Stable Data Patterns: Apply
@Immutable and @Stable to data classes and state containers to reduce conservative recomposition behavior.
- Canvas-Based Gauges & Graphs: Render gauges and live line graphs using
Canvas so drawing work stays in the draw phase with minimal composition churn.
- Lifecycle-Safe Flow Collection: Prefer
collectAsStateWithLifecycle for StateFlow-to-Compose wiring, preventing leaks and unwanted updates.
Quick Start
Optimize a Compose real-time dashboard that updates at 25Hz or faster by splitting the telemetry stream into per-metric StateFlows, filtering with distinctUntilChanged(), and rendering gauges/graphs with Canvas and derived state.