跪拜 Guibai
← Back to the summary

Android Jank: Which Thread Actually Cost You the Frame?

Jank Attribution: From UI Thread to RenderThread

This article is translated from "Android UI thread vs. RenderThread: what actually happens when a frame is drawn", published by Ravi Rawal on November 18, 2026.

0.png

Even if your Android app's main thread is non-blocking, dropped frames can still occur. This seems strange, because we know that drawing a frame requires multiple components. And our code only runs in the first component.

The UI thread is responsible for handling application-side operations and recording drawing commands. A native thread (RenderThread) receives these records and performs actual rendering. Then the GPU executes the graphics commands, and SurfaceFlinger composites the app's buffer with everything else on screen.

When debugging dropped frames, this can be confusing: slow operations in onDraw() and GPU overload look identical to the user, but require different solutions. Moving code to a background thread only solves one of them. To pinpoint the specific problem, track how the frame moves through the rendering pipeline.

What the UI thread does

Every application has a main thread, often called the UI thread. It manages the main message queue, runs lifecycle callbacks, input events, and all tasks posted to the main Looper. For the view system, it also applies property changes, measures and lays out the view hierarchy, runs animation callbacks, calls View.draw() and your onDraw() method, and records drawing operations for hardware-accelerated rendering.

The last point is easy to miss. In hardware acceleration, onDraw() does not do any rasterization. Your Canvas calls are recorded into a display list, and each View maintains its own display list (a RenderNode). Here is an example of a simple custom view:

class ProgressView(context: Context) : View(context) {
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private var progress = 0.5f
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.drawCircle(width / 2f, height / 2f, width * progress / 2f, paint)
    }
}

When invalidate() schedules a redraw, the framework calls onDraw() during the next frame traversal (on the UI thread), at which point the circle is recorded, not drawn.

That's why custom views can cause jank even when the GPU is nearly idle.

If onDraw() performs heavy calculations, allocates large temporary objects, or loops over thousands of elements, the UI thread spends time there, and the GPU can't process frames that haven't been submitted yet.

Android's rendering performance documentation describes the same division: recording phase on the UI thread, then drawing phase on RenderThread.

What RenderThread does

RenderThread is a native thread in the hardware-accelerated rendering path. It does not run your UI code. It receives display lists recorded by the UI thread, replays them through HWUI (Android's Skia-based renderer), and sends the generated commands to the graphics driver.

So the three phases can be divided like this:

  1. UI thread decides how the UI looks and records it.
  2. RenderThread replays the records and submits graphics commands.
  3. GPU rasterizes and shades.

In system traces, these two CPU phases appear as Record View#draw() on the main thread and DrawFrame on RenderThread. Separating them allows Android to overlap frame preparation with rendering, instead of pushing everything onto the application thread.

Even if Canvas calls look lightweight, RenderThread performs some expensive work. On many devices, large Path objects are rasterized on the CPU and uploaded to the GPU, and clipPath() increases rendering cost. Harmless-looking calls in application code can become a performance bottleneck in later stages.

RenderThread can also run some animations independently. ViewPropertyAnimator and ripple effects can continue running while the main thread is busy, which is one reason they stay smooth.

One frame, from start to finish

Suppose the user is scrolling a RecyclerView. Scrolling moves content and may bring new items into view. This frame goes through these stages:

1 (2).png

The stages overlap between frames; if a frame doesn't need to change anything, most stages are skipped. The order is:

  1. When the VSync signal arrives, Choreographer runs frame callbacks on the main thread's Looper. Input, animations, and view traversal begin.
  2. UI thread processes state changes, performs layout if something changed, and records drawing operations. Not every frame needs full measure and layout. If only draw properties (such as translationX or alpha) change, the framework can usually skip layout and often reuse existing display lists. This is why animating translationX is more efficient than animating margins (which force layout every frame).
  3. UI thread hands off recorded work to RenderThread. RenderThread processes it, builds graphics commands, and submits to the driver.
  4. GPU executes the commands. From the CPU's perspective, this is asynchronous: submitting commands doesn't mean the GPU has finished executing.
  5. SurfaceFlinger composites the app's buffer with system surfaces and presents the result. The app has no control over this last stage.

So completing View.draw() doesn't mean the frame is on the screen. Rendering, buffer availability, composition, and presentation still need to happen.

Why threads wait for each other

These two threads cannot run fully independently.

The UI thread owns UI state, and RenderThread needs a consistent snapshot of that state.

In traces, you'll see syncFrameState: the main thread blocks while RenderThread copies the needed state. This is intentional, because allowing both threads to access shared state concurrently would cause frame inconsistency. Large bitmaps can make sync slow, because they may need to be moved to GPU-accessible memory before drawing.

RenderThread may also wait for the compositor.

When it requests or returns a buffer (dequeueBuffer, eglSwapBuffers), it blocks if the GPU or SurfaceFlinger is slow to respond. These waits are not bugs by themselves. A thread that looks idle in a trace may simply be waiting for an earlier stage, so before blaming a thread, look at the whole frame.

Why RenderThread cannot prevent jank

People often think a dedicated RenderThread should avoid resource-heavy UI operations. But that's not the case, because RenderThread can only draw what the UI thread has recorded. Three examples show the difference.

Slow drawing code. Suppose your onDraw() looks like this:

override fun onDraw(canvas: Canvas) {
    super.onDraw(canvas)
    val points = generateComplexGeometry()
    points.forEach { point ->
        canvas.drawCircle(point.x, point.y, point.radius, paint)
    }
}

If generateComplexGeometry() is slow, it runs on the UI thread every frame. RenderThread waits for the display list that arrives late, the GPU stays nearly idle, and the frame still misses its deadline. So compute geometry once, cache it, and recompute only when input changes.

Slow draw commands. Now the UI thread records only a few commands, taking well under a millisecond, but these commands contain a large clipPath or Path. Recording is quick, but DrawFrame runs for a long time. Moving your code to a worker thread doesn't solve this, because the cost is in the commands themselves. Simplify them.

GPU overload. Both CPU threads finish on time, but the GPU rendering is late. Large textures, overdraw, and heavy shaders are common causes. Optimizing onDraw() doesn't help, because the delay occurs after rendering submission.

The on-screen symptom can be identical, so pay attention to where the time is actually spent:

2.png

Moving work off the main thread only helps the first line.

What changes with Jetpack Compose

Compose introduces new semantics for describing and updating UI, but the underlying graphics pipeline stays the same. The pipeline has three phases: Compose (composition), Layout, and Draw. All these run on the UI thread, and the Draw phase writes to the same render nodes. So the same mechanisms still apply: slow composition or layout delays frame preparation, slow draw commands slow RenderThread, and a busy or saturated GPU causes frame delay after all app work completes.

Compose lets you specify which phase a state read happens in. Reading state during composition re-runs composition. Reading the same state inside a graphicsLayer lambda only re-runs the draw phase:

val alpha = animateFloatAsState(if (visible) 1f else 0f)
Box(Modifier.graphicsLayer { this.alpha = alpha.value }) // no recomposition per frame

To determine whether a problem comes from Compose or the whole pipeline, enable composition tracing and capture a system trace.

Finding the bottleneck in traces

Android Studio's profiler and Perfetto can both record system traces that show the main thread, RenderThread, GPU completion, and frame events. The workflow is:

  1. Reproduce the janky interaction and record a trace.
  2. On Android 12 (API 31) and above, find delayed frames in the "janky frames" trace. Perfetto's FrameTimeline compares expected and actual display times to tell you whether frames reached the screen on time.
  3. Look for slow Choreographer#doFrame calls on the main thread, including layout and draw operations.
  4. Look for slow DrawFrame calls on RenderThread.
  5. Check when GPU work finishes.

3.png

Don't stop at the first long segment you see.

A long RenderThread execution doesn't necessarily mean the GPU is slow. Similarly, a late GPU render finish doesn't necessarily mean the UI thread has a problem.

If you want to catch regressions without manual tracing, Macrobenchmark's FrameTimingMetric and the JankStats library automatically provide frame timing information.

The frame interval is 16.7 ms at 60Hz, 11.1 ms at 90Hz, and 8.3 ms at 120Hz.

That's the interval between two refreshes, not including scheduling time. Sync, rendering, and compositing all take part of it.

Also, frames are pipelined. So the time a thread spends on a frame is not the same as the latency from when the user touches the screen to when they see the result.

Measure the entire frame lifecycle, rather than treating 16 ms as a budget for your code.

We welcome you to search and follow the WeChat official account "稀有猿诉" for more quality articles!

Protect originality, do not repost!