Android Jank: Which Thread Actually Cost You the Frame?
Misdiagnosing jank wastes hours: the fix for a UI-thread bottleneck (move code off main) is useless for a GPU-limited frame, and simplifying draw commands does nothing for a main-thread stall. This breakdown tells you which stage to profile and which change actually reduces dropped frames.
Android frames pass through three handoffs: the UI thread records display lists, RenderThread replays them and submits commands, and the GPU rasterizes before SurfaceFlinger composes. The same dropped-frame symptom can come from any one of these. A heavy computation in onDraw() starves RenderThread because no commands are recorded; a large Path or clipPath slows DrawFrame even though recording was cheap; and a saturated GPU delays rendering after both CPU threads are done.
Moving work to a background thread only helps the first case. The trace markers differ: Record View#draw() runs on the main thread, DrawFrame on RenderThread, and GPU completion is separate. Perfetto's FrameTimeline on Android 12+ compares expected vs actual display time to isolate the stage. For Compose, the pipeline stays the same, but state reads can be scoped inside a graphicsLayer lambda to avoid recomposition per frame.
The frame interval is 16.7 ms at 60Hz, 11.1 ms at 90Hz, and 8.3 ms at 120Hz. Because frames pipeline, that number is not a per-thread budget; measuring the whole frame lifecycle matters more than slicing thread segments.
Because onDraw() only records rather than rasterizes, moving heavy logic off the UI thread does nothing when the real cost is in RenderThread's expensive command replay or in GPU execution.
Thread waits like syncFrameState and buffer returns are intentional, so a long idle segment in a trace often means the thread is waiting on a later stage; a single isolated segment can mislead debugging.
Frame pipelining means a thread's processing time is not the same as the latency from touch to screen, so treating 16 ms as a per-thread budget is a category error.