The ViewModel Performance Trap: When State Management Bites Back
summary
Argument: ViewModel misuse causes real startup and rendering latency — init blocks, eager DI, reflective JSON parsers and deprecated Retrofit paths create hidden work (10–20 ms per parser, thousands of lazy injections in one app) that delays first frame. Detection uses Perfetto traces and method-sampling plus logs and custom metrics. Fixes that work include pass a custom CoroutineScope into ViewModel to avoid mainImmediate, warming expensive dependencies and early prefetch cuts TTI by 300–600 ms when applied.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:50What is a ViewModel
- 4:16Misusing ViewModels
- 9:31ViewModel performance sampling
- 13:01Eager dependency costs
- 16:12Abusing init blocks
- 20:47ViewModel scope and coroutines
- 23:57Customizing ViewModel scope
- 26:23Fetching beyond init
- 30:55Prefetching during navigation
- 33:00Myth of coroutine parallelization
- 35:48ViewModel as state holder
- 37:55Measuring perceived performance
- 39:21Q&A
- 41:52Q&A: Dispatcher switching
- 45:20Q&A: IO dispatcher use








