Jank & Rendering Flashcards
PERFORMANCE › Runtime
- What is the per-frame budget at 60fps, 90fps, and 120fps, and what happens if you exceed it?
- About 16ms at 60fps, ~11ms at 90fps, ~8ms at 120fps. If a frame's work overruns the budget, Choreographer drops the entire frame, producing visible jank (a stutter or skipped frame).
- How does Android define slow frames vs frozen frames, and what are the vitals bad-behavior thresholds?
- Slow frames take longer than 16ms; frozen frames take longer than 700ms. Android vitals flags slow rendering when about 25% or more of frames exceed 16ms, and frozen frames when about 0.1% or more exceed 700ms.
- Walk through the two main stages of the Android rendering pipeline.
- On the UI/main thread, a Choreographer callback drives input, animation, measure, layout, and View#draw, which records drawing commands into a display list. RenderThread then executes DrawFrame: syncs the display list, uploads textures, and issues GPU draw calls. Both must finish within the frame budget.
- What is overdraw and how do you diagnose and fix it?
- Overdraw is painting the same pixel multiple times in one frame, wasting GPU fill rate. Diagnose with Developer Options > Debug GPU Overdraw, where the color overlay shows how many times each pixel was drawn; aim for true color or blue (1x). Fix by removing redundant backgrounds, flattening layers, and clipping.
- Why is work on the main thread a primary jank cause, and how do you fix it?
- The main/UI thread produces frames, so blocking it with disk/network I/O, heavy parsing, large allocations, or synchronous Binder IPC starves frame deadlines and drops frames. Move that work to background dispatchers/coroutines or other threads, leaving only lightweight UI updates on the main thread.
- How does Macrobenchmark measure jank and where does it run?
- Its FrameTimingMetric captures per-frame durations (e.g., frameDurationCpuMs and frameOverrunMs) as P50/P90/P99 percentiles while driving real UI interactions on a physical device in a separate process against a release-like (non-debuggable, profileable) build, making it ideal for CI regression tracking.
- What is JankStats and when would you use it over Macrobenchmark?
- JankStats is an AndroidX library for production/field jank monitoring. It uses FrameMetrics on API 24+ (with heuristics below) and reports per-frame FrameData (duration, isJank, and attached UI state), letting you attribute real-user jank to specific screens or states, whereas Macrobenchmark is for the lab/CI.
- What causes Compose recomposition to become a jank source, and how do you mitigate it?
- Excessive or unnecessary recomposition from unstable parameters, reading state too high in the tree, or allocating lambdas/objects during composition. Mitigate with stable/immutable types, scoping state reads low, remember and derivedStateOf, keys on lazy lists, and shipping a baseline profile to avoid JIT-driven first-run jank.
- What is the difference between a frozen frame and an ANR?
- A frozen frame takes 700ms to ~5s to render: severe jank where the app looks stuck but recovers. An ANR fires when the main thread is unresponsive for roughly 5s or more, showing the system Application Not Responding dialog. ANR rate is a core Play vital; slow/frozen rendering is a non-core vital.