Rendering performanceNew
Repaint only what changed with partial redraw, see each frame's damage with the debug overlay, count recompositions, and let idle windows give their GPU memory back.
This page covers how a Nucleus window renders its frames: partial redraw, the debug switches that
show what each frame repaints, and what an idle window does. Everything here comes with
nucleus-application and works on macOS, Windows and Linux, on the JVM and in a native image.
Turn on partial redraw
With partial redraw on, a frame repaints and presents only the part of the window that changed since the previous one, instead of the whole window. A blinking cursor or a spinner then repaints only its own area, and a window where nothing moves presents no frame at all.
Partial redraw is off by default. Turn it on with the partialRedraw knob of the
startup pack, or with the whole pack:
nucleus.application {
nucleusOptimization { partialRedraw = true }
// or: nucleusOptimization = true
}The knob patches Compose's render layers at build time, so the runtime can tell which layers
changed, and turns the runtime on. Your source code stays the same. It applies to the run task,
to packaged apps and to GraalVM native images.
Pass -Dnucleus.tao.partialRedraw=false to repaint every frame in full for one run, or true to
force it on.
See what each frame repaints
The debug { } block turns on overlays and logs for the run task. Packages, runDistributable
and native images never get them.
nucleus.application {
nucleusOptimization { partialRedraw = true }
debug {
partialRedraw {
tint = true // flash what each frame changed in red
stats = true // log how much of the window frames repaint
}
}
}| Switch | Effect |
|---|---|
tint | Flashes what each frame repainted in translucent red, every other frame, like Android's "Show GPU view updates". A frame repainted in full flashes the whole window. |
stats | Logs every few seconds how much of the window frames repaint and which layers damaged them, and why frames repaint in full when that reason changes. |
verify | Renders every partial frame again in full off screen and logs any pixel that differs. Slow, and turns tint off. |
To turn a switch on for one run without editing the build, pass the comma-separated
nucleus.debug Gradle property:
./gradlew run -Pnucleus.debug=tint,statsA flash larger than what moved means the frame repainted more than it needed. The usual cause is a layer that does not clip its content or casts a shadow: its damage is then its nearest clipping ancestor's bounds. The partial redraw switches need partial redraw on; otherwise the build warns and every frame repaints in full.

Count recompositions
recomposition logs the composables that ran the most, every few seconds, first composition
included. It works with or without partial redraw.
nucleus.application {
debug {
recomposition {
enabled = true
top = 20 // composables per report, default 10
}
}
}-Pnucleus.debug=recomposition turns it on for one run.
Idle windows
A window renders a frame only when its content changes. A coroutine on Dispatchers.Main, such as
a delay loop, a clock or a withContext(Dispatchers.Main) hop, runs between frames and does not
render one by itself.
Once a window has drawn nothing for 3 seconds, or as soon as it is minimized, Nucleus releases the GPU resources Skia cached for it: the textures an animation or an image-heavy screen uploaded. The next frame recreates what it needs. A window with a live GPU render context consumer keeps its cache. There is nothing to configure.
On macOS, a window out of sight renders nothing: a hidden app, a covered window, a window on another Space or behind a locked screen skips its frames, animations included, and resumes when it shows again. The display link stops 500 ms after the last frame, the accessibility sync waits for an assistive client to connect, and the single-instance watcher uses FSEvents instead of polling. A hidden app falls from about 14 % CPU to under 1 %, so the Mac can sleep.
Notes
- Some frames always repaint in full: the first one, a resize, a change of window background or corner, a frame while a popup is open, and the frame after a layer that draws content recorded elsewhere, such as a backdrop blur.
- Under macOS and Windows, a frame whose changes cover 80 % of the window or more repaints in full, which costs less there than a partial frame.
- The build-time patch only exists in builds of the Nucleus plugin. An app started from the IDE
without the plugin's
runtask, or under hot reload, repaints every frame in full. - Compose deactivates a lazy-list item scrolled out of view after the frame instead of inside it.
Pass
-Dnucleus.tao.outOfFrameExecutor=falseto go back to deactivating it inside the frame. - On Windows, a window that overhangs the desktop, such as a maximized or fullscreen one, presents
through a DirectComposition mirror. GPUs below Direct3D feature level 11_0 (WDDM 1.1 drivers,
where the mirror turns black) repaint on move instead. Pass
-Dnucleus.tao.windowsFrameMirror=falseto do the same on a driver that misbehaves above that level.SystemInfo.renderTier()reports such GPUs asLEGACY.
What's next
- Startup optimization: the other
nucleusOptimizationknobs. - Benchmarks: rendering ramps on the JVM and in a native image.
- GPU render context: render into a window with your own GPU code.
Last updated on
Startup optimization
Turn on the nucleusOptimization pack to shorten JVM startup and lower idle memory, and package the app with the current OpenJDK through lastJdk.
AOT cache
Generate a Project Leyden AOT cache at build time and ship it in every installer, so the JVM skips most of its warmup at launch.