As asked
A junior engineer has a ViewModel that parses a large JSON response and builds a complex UI model directly inside a StateFlow update, all on the main thread. Users report UI jank. You are doing the code review. What do you say and how do you suggest fixing it?
Sample answer outline
The fix is moving the heavy computation to withContext(Dispatchers.Default) inside the ViewModel's coroutine. The review comment should explain why: the main thread has a 16ms frame budget and blocking it causes dropped frames. The candidate should also mention testing the fix with a profiler and suggest adding a custom lint rule or a performance test that measures the computation time.
Expect these follow-ups
- How do you determine the right dispatcher for a task: Default vs IO?
- What would you check to confirm the jank is gone after the fix?