Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

What a frame costs

A native window is up in a tenth of a second, a settled frame costs microseconds, and this page says where the rest of the time goes.

Read this page to know which numbers to expect from a Goldberry window and what each one measures. The three chapters after it say how to start fast, how to keep a frame cheap, and how to measure your own application rather than trust these figures.

519msnative image, from exec to the first frame; the window is open at 116.2 ms
1980msthe same application on a cold JVM; 1340 ms with a JDK 25 AOT cache
3.13msmedian frame at 960×640 with a wrapped paragraph, paced to the display
2.3msa full 3840×2160 raster across four paint workers
117µsrepainting one small change, drawing only the damage
9.1µsa frame in which nothing changed: layout and the walk on the retained tree

The table below says what each number measures, and how.

NumberWhat it measuresMethod
519 ms, 116 msThe showcase’s native image, from exec to the first frame, and the moment the window is openmedian of 7 runs, timed from exec
1980 ms, 1340 msThe showcase on the JVM, cold and with an AOT cachemedian of 5 runs
3.13 ms, 4.28 msA 960×640 frame with text, paced to the displaymedian and 95th percentile
2.3 msA 3840×2160 paint in PaintBenchmarkfour paint workers, against 6.0 ms on one thread
117 µsOne small box changed at 960×640, repainted inside its damageagainst 367 µs for a full repaint
9.1 µsLayout and the walk on a showcase-shaped tree when nothing changedthe retained tree, against 190 µs rebuilt every frame

The frame loop

One UI thread runs the loop. Paint workers rasterize the bands. This is the pipeline, in the order a frame runs it:

input events → dispatch (hit-test on render tree)
→ rebuild dirty widgets → diff → update elements/render objects
→ style resolution (invalidated nodes) → layout (incremental)
→ paint recording (dirty layers only) → raster (banded)
→ present(buffer, damage) / GPU composite

Three trees take part. Widgets are immutable records that describe. Elements persist and hold state. Render objects own the layout nodes and are kept between frames, so a frame diffs a new description against a retained tree rather than building one. The architecture overview has the full picture.

Where the time goes at 960×640

Everything before rasterization is a rounding error. Rasterization and present are the frame.

StageCostNote
Everything but rasterization, nothing changed3.5 µsagainst 354 µs with nothing retained or cached
Rasterization on one threadabout 320 µsthe whole frame, with the rasterizer pinned to one thread
Paint in a live window, four workers2.146 msagainst 2.856 ms synchronous
Present, unpacedabout 6.4 ms4.8 ms of it blocks on the swapchain and 43 µs is the toolkit’s own code
Present, paced to the display1.20 mspaint falls to 1.61 ms beside it

Read the paint row with care. The same scene paints in 0.34 ms in a benchmark loop and in 2.15 ms in a running window, because present leaves the next paint’s caches cold. Only a figure from a live window says what a frame costs. Measuring explains the gap.

The three chapters