Stipple

Performance: what a frame costs, and how to keep it small

A Stipple view is a function of the state: each time something changes, the app builds the view again, lowers it (interaction states, transitions), lays it out, paints it into a scene, works out what changed since the frame on screen, and rasterizes only that. This page is about keeping those steps cheap for large, animated interfaces: memoized subtrees and derived values in the view, animation frames that skip the view altogether, and painting only what shows.

Memoized subtrees: Cx::memo

cx.memo(key, deps, |cx| element) keeps the element the closure built under key, with a hash of deps. While deps hash the same, later builds return the kept element without calling the closure:

fn view(s: &Inbox, cx: &mut Cx<Inbox>) -> Element {
    let rows = s.messages.iter().enumerate().map(|(i, m)| {
        // Built again only when this message changes.
        cx.memo(("message", m.id), (m.revision, i == s.selected), |cx| {
            message_row(cx, m, i)
        })
    });
    column(rows.collect())
}
  • Handlers come along. The closure gets the Cx, so the subtree can have tap, key, drag, drop, pointer and context handlers, focus and scroll containers. When it is reused, the handlers it registered last time are moved over from the previous frame's table under the same ids, so clicks on a reused row reach the handler built with it. They are the ones built with those deps, so give deps everything a handler captures that can change.
  • Ids stay right. Handler ids are handed out in registration order, so a kept subtree is reused only where its ids come out the same: when everything built before it registered as many handlers of each kind (and scroll containers) as last time. If a button appears above it, it is built again once, then kept at its new place. An id a handler captured (a ScrollId to scroll from a button, a FocusId) is therefore never stale.
  • **What it reads through Cx is an input.** The interaction states (cx.interaction), drop-target states (cx.drop_state), scroll offsets (cx.scroll_offset, which virtual_list reads) and window info (cx.window_info) it read are recorded and compared, as are the theme, the window's size and its focus. A reused subtree still counts as having read them: the app rebuilds when they change, and the subtree is built again.
  • Some subtrees are never kept: one that asks for frames (request_frame, animate, play), declares overlays or context menus (Element::context_menu), or sets the window title. frame_time isn't tracked, so sample animations outside a memoized closure.
  • Layout comes along too. A reused subtree that lowers to the same elements as last time (no state override or transition inside it changed anything) isn't measured or laid out again: its last layout is moved to where it now goes.
  • Keys are per window and should be unique within a build (a second use of a key in the same build is built afresh, not kept). Nested memos are kept with the subtree around them. Whatever a build didn't use is dropped.

deps are hashed (with the standard library's SipHash), not compared, so anything Hash works, &str and slices of the state included, without cloning.

Derived values: Cx::derive

cx.derive(key, deps, || value) caches a value the same way: computed again only when deps change, cloned out otherwise (wrap a large one in an Rc). For something costly derived from the state that the view needs on every build: a sorted, filtered list, totals, a parsed document.

let visible = cx.derive("visible", (&s.items, &s.filter), || {
    Rc::new(s.items.iter().filter(|i| i.matches(&s.filter)).cloned().collect::<Vec<_>>())
});

Animation frames without a build

Implicit transitions of looks that don't move the layout — fill, border, corner radius, text color, opacity and transform — and the hover and press highlights fading don't need the view: when the only thing that changed since the frame on screen is time, the app takes the laid-out tree on screen, writes the in-flight values on the moving elements, and paints. The view isn't built and nothing is laid out. The damage is the moving elements' old and new extents (a recolored element: its own box; a moved or faded one: everything it draws, where it was and where it is), so only that is rasterized and presented.

Frames fall back to a full build when the view asked for them itself (Cx::request_frame / Cx::animate: it samples the frame time, so only it knows what changes), when padding or a fixed size is animating, during enter, exit and layout animations, OS-drawn controls cross-fading between states, a touch fling or a drop target's drag-over fade, and when something moving changes what the pointer is over for an element whose look (or the view) depends on that.

So prefer a transition over sampling an Animated in the view when the view doesn't need the value: .transform(t).transition(...) animates without builds, cx.animate(&anim) builds every frame.

Painting only what shows

The scene for a frame leaves out what is drawn entirely outside the window or outside a clip (a scroll container, a clipped panel): the rows of a long list scrolled out of view aren't shaped or put in the scene, and raster work follows what is visible. (core::paint_visible does it for a custom pipeline; it assumes nothing draws more than core::CULL_MARGIN, 16 logical pixels, past its box.) For lists of thousands of rows, also build only what is visible: see virtual_list.

What it buys

bench_a_large_list_with_one_moving_element in src/reactivity_tests.rs (cargo test --release bench_ -- --nocapture) times a frame of 500 rows in a scroll container with one moving element, 800×600, on the software renderer. On a Linux desktop (a busy one; medians over 60 frames):

FrameBuild and damageRaster and presentDamage
Before: transition moving one tile3.3 ms1.1 ms1345 px²
Now: the same, drawn without a build0.12 ms0.04 ms1344 px²
Before: the view turns a spinner itself3.6 ms1.4 ms~1600 px²
Now: the same0.88 ms0.05 ms~1250 px²
Now: the same, rows memoized0.73 ms0.05 ms~1600 px²

The damage was already limited to what moved; what was spent was everything around it (shaping and painting all 500 rows into the scene, and rasterizing that scene for a 40×30 region).

What a built frame still costs grows with the tree: building or cloning it, lowering it, comparing it with the last one and keeping a copy are walks over every element. A memoized subtree saves building and laying out, not those walks; a view with very cheap rows gains little from it, one with costly rows (formatting, data work) much more.

Benchmarks

examples/bench times what a user feels, on the software renderer and on the GPU one, and CI runs it on every push (the Perf workflow, see CI). Each scenario runs a fixed number of iterations after a warm-up, with fixed sizes and a fixed seed, and reports the median and the 95th percentile:

ScenarioWhat is timed
first_frame_1x, first_frame_2xThe whole first frame of a window of widgets (a toolbar, a text field, 32 rows of checkboxes, switches, sliders, buttons and progress bars, a 10,000-row virtual_list), 1024×768 at scale 1 and 2
hoverThe pointer moving onto another button, to the frame ready; and the pixels rasterized (only the damage is)
scroll_listA wheel step (48 px) over the 10,000-row list, to the frame ready
type_charA character typed into the focused text field, to the frame ready
theme_switchA click on a button switching light and dark, to the frame ready
sprites_20002000 32×32 sprites over a 1920×1080 background (the spritedemo --bench scene), read back
gallery_4kThe widget window at 3840×2160 (1920×1080 at scale 2), a whole frame drawn from its scene; on a GPU offscreen, waiting for it, not read back (what a frame presented to a window costs); texture_mb: the texture memory the GPU's caches hold after it
sprites_10k10 000 sprites from a SpriteSheet over a 3840×2160 background, likewise
canvas_rowOne row of a 120×40 grid of characters drawn in an Element::canvas changed and invalidated, to the frame ready; on a GPU only the row is rasterized and uploaded into the canvas's texture (upload_kb)
canvas_full_1x, canvas_full_2xEvery cell of a 200×60 terminal grid (8×16 cells, stretches of up to 24 cells in 8 colors, a quarter on colored backgrounds, a glyph run each) changed and the whole canvas invalidated, to the frame ready, at scale 1 and 2: cat of a big file, or a full-screen program redrawing
canvas_scrollThe same grid scrolled up a line with scroll_canvas_rect (its pixels moved) and the new bottom line painted, to the frame ready
transitionEach frame of a page pushed and popped on a nav_stack and a bottom sheet opened and dismissed, animating, on a phone-sized window (390×844 at scale 3)
layout_treeLaying out a tree of ~4,000 elements
text_layout, text_layout_cold, text_layout_cjkLaying out a 400-word paragraph wrapped at 560 px: with shaping cached, with a font just loaded, and 1,200 Japanese characters through the system's CJK fallback (when there is one)
startupLoading the system font, making the app and drawing its first frame
calibrationA fixed CPU loop: how fast the machine was during the run

"To the frame ready" is the event and the frame that answers it, presented as a window's frame is (App::present_frame): built, laid out, painted, and rasterized (only the damage, on the CPU) or drawn on the GPU and read back. Layout and text don't draw, so they run with the software renderer only.

cargo run --release --example bench                                   # the software renderer
cargo run --release --example bench --features mtl -- --renderer metal  # gl (--features gl), d3d11 (--features d3d)
cargo run --release --example bench -- --only hover,type_char --json out.json

On a GPU renderer, first_frame_*, hover and sprites_2000 also report how many draw calls their last frame took (draw_calls, from stipple::gpu::last_frame_draw_calls).

--quick runs a third of the iterations, --list names the scenarios. Asking for a GPU renderer the machine doesn't have measures the software one instead, and the report says so (gpu_unavailable). The JSON holds each scenario's median, p95, minimum and samples, the run's calibration_ms, and on a GPU the device it drew on (gpu_device, from stipple::gpu::device_name) and whether that is a hardware GPU (gpu_hardware: not llvmpipe, lavapipe, SwiftShader, WARP or a virtual machine's paravirtual device). The memory figures come from stipple::gpu::stats.

On an Apple M5 Max (macOS, release build; Chrome 157 for the browser, where these scenarios run in the module on the CPU):

ScenarioSoftwareMetalChrome (wasm, software)
gallery_4k357 ms0.76 ms, 1 MB of textures3.7 s
sprites_10k18 ms2.6 ms, 34 MB of textures27 ms
canvas_row0.03 ms (18 432 pixels)0.93 ms (74 kB uploaded)1.4 ms
canvas_full_1x3.2 ms6.6 ms—
canvas_full_2x6.2 ms9.0 ms—
canvas_scroll0.23 ms (25 600 pixels)2.9 ms—
transition (per frame)103 ms3.5 ms (p95 4.1)494 ms

On Linux with an NVIDIA GeForce RTX 5080 (release build, November 2026), Vulkan meets the hardware targets and OpenGL ES (NVIDIA's EGL) misses two:

ScenarioSoftwareVulkanOpenGL ES
gallery_4k29 ms0.33 ms5.7 ms
sprites_10k20 ms1.07 ms7.7 ms
canvas_row0.62 ms1.09 ms1.06 ms
transition (per frame, p95)57 ms2.9 ms3.2 ms

That's why Renderer::Auto picks Vulkan on X11 and leaves OpenGL ES to an explicit choice (gpu.md). The report's gpu_hardware comes from stipple::gpu::is_hardware_device, the test Renderer::Auto makes too.

The software renderer's transition frames are whole 1170×2532 frames, which is why phones draw on the GPU.

On a phone. The benchmark draws offscreen, so it runs as a plain executable: over adb on an Android phone or emulator, spawned in the iOS simulator. tools/gpu-mobile.sh builds it for the device, runs it and brings the JSON back (and runs the GPU comparison corpus the same way, gpu.md):

tools/gpu-mobile.sh android bench --json phone.json                      # Vulkan where it's built and works
tools/gpu-mobile.sh android bench --renderer gl --only transition,canvas_row
tools/gpu-mobile.sh ios-sim bench --json sim.json                        # Metal, in the simulator
tools/gpu-mobile.sh android corpus vk                                    # the corpus (gl or vk; ios-sim: Metal)
python3 tools/bench/compare.py phone.json

--renderer vulkan and --renderer gl pick the API in a build with both (--renderer gpu takes Vulkan first on Linux and Android). A physical iPhone runs only signed apps, so on iOS it's the simulator for now.

Its transition frames are held to 8.3 ms at the 95th percentile (120 Hz; perf/budgets.json, platforms android and ios). CI runs both in the simulator and on the API 34 emulator (gpu-ios-sim, gpu-android in visual.yml, both required), and compile-checks the benchmark for phones (the mobile job in ci.yml). Locally (November 2026), in the iOS 27 simulator and on an API 35 arm64 emulator with the host's GPU, both on an Apple M5 Max, so a desktop GPU behind a translation layer, not a phone's:

ScenarioiOS simulator, softwareiOS simulator, MetalEmulator, VulkanEmulator, OpenGL ES
gallery_4k19 ms0.96 ms1.6 ms13 ms
sprites_10k25 ms3.1 ms5.2 ms17 ms
canvas_row0.41 ms1.7 ms2.4 ms2.7 ms
transition (per frame, p95)42 ms5.6 ms6.7 ms8.4 ms

On the emulator's default SwiftShader (as on CI) the GPU numbers are several times those, and gpu_hardware is false.

In the browser, the same scenarios run in the wasm module on the software renderer (its GPU renderers draw into the page's canvas only), and the page also runs the app live and times events dispatched to the canvas (a hover, a wheel step, a key, a click on "Theme") to the next frame presented after them: web_hover, web_scroll_list, web_type_char, web_theme_switch, as median_ms (which includes waiting for the display's next frame) and work_ms (the time in the event handler and the frame callback), on the software renderer, WebGL2 and WebGPU:

cargo build --release --target wasm32-unknown-unknown --features gpu --example bench_web
python3 tools/bench/run_web.py --out target/bench                 # software, webgl2, webgpu
python3 tools/bench/run_web.py --renderer software --swiftshader  # as on CI: no GPU, SwiftShader

Baselines and budgets

tools/bench/compare.py compares a run with its baseline, perf/baseline/<runner>-<renderer>.json (linux, macos, windows, web × software, gl, metal, d3d11, webgl2, webgpu). The baseline's median is first scaled by how fast each machine was (the ratio of the two runs' calibration_ms, clamped to 1/3–3), then a scenario fails when it is more than its threshold times that (1.5× by default) and more than min_delta_ms slower. With --rerun, the failing scenarios are measured again and only one that fails both times fails the check. A missing baseline records only; a "provisional": true one reports without failing.

The budgets are hard limits, whatever the baseline: on the desktop runners, hover and type_char must be ready within 16 ms (one frame at 60 Hz) on the software renderer and Metal; scroll_list (16 ms) and theme_switch (100 ms) warn for now, as do the browser's web_hover and web_type_char work (16 ms). canvas_row, canvas_full_1x and canvas_scroll must be ready within 16 ms on the software renderer, and canvas_full_2x warns past it (it warns past it on a GPU too, as the others do on a hardware one). Thresholds and budgets live in perf/budgets.json.

The GPU targets depend on the device, so a budget can say "hardware": true (checked only when the report's gpu_hardware is) or false (only on a software GPU). On a hardware GPU, gallery_4k and sprites_10k must draw within 4 ms and transition frames within 8.3 ms (p95); CI's runners have no GPU (llvmpipe, WARP, SwiftShader, the macOS VM's paravirtual Metal), so there they only warn past a 250 ms ceiling, and the hardware targets are checked wherever the benchmark runs on a real GPU (python3 tools/bench/compare.py out.json on your machine). Memory budgets cap the texture memory the GPU's caches hold after gallery_4k (32 MB) and sprites_10k (48 MB: the 4K background is 33 MB), with max in place of ms. A scenario not in the baseline yet is reported without being compared.

To take new baselines, run the Perf workflow by hand with update_baseline ticked (it commits the run's reports to perf/baseline/), or download a run's reports and copy them in:

python3 tools/bench/update_baseline.py --run <run id>       # needs gh
python3 tools/bench/update_baseline.py --from target/bench --provisional --note "my machine"

Each workflow run's summary shows the tables (baseline, expected after scaling, now, delta, budget), and its artifacts hold the JSON (perf-linux, perf-macos, perf-windows, perf-web).

On the web

A Stipple app in a browser is the same code compiled to WebAssembly, so a frame costs what it does natively plus what wasm loses (no threads, 128-bit SIMD at best, a slower allocator). What the site does to keep the examples responsive, and what you can do for your own app:

  • Draw on the GPU when there is one. renderer: "auto" (the default) draws with WebGPU, else WebGL2, when the browser runs them on a hardware GPU and the module was built with the gpu feature; on a software one (SwiftShader, llvmpipe: a machine or VM without a GPU, some headless browsers) it stays on the CPU, which is faster there. stipple.js asks WebGL2 for a context with failIfMajorPerformanceCaveat and reads the renderer's name (WEBGL_debug_renderer_info) once per page. On the GPU a frame costs well under a millisecond of the page's time whatever changed; on the CPU it costs what the damage covers, four times the pixels at a pixel ratio of 2.
  • Build for speed. The site builds its modules with SIMD (-C target-feature=+simd128, which every current browser runs), link-time optimization and one codegen unit, then runs wasm-opt -O2 over them ([build.env] and [build.wasm-opt] in tools/site/examples.toml). SIMD and LTO make the CPU renderer about a quarter faster; wasm-opt takes 15% off the size (2.85 → 2.43 MB, 0.9 MB compressed).
  • Current dependencies. Stipple needs Rust 1.95, and with it the oxideav releases that are much faster than the ones before: oxideav-raster 0.1.4 stopped rasterizing every path and clip into a mask the size of the window (a full frame of widgetsdemo at 2560×1504 went from 370 to 40 ms in the browser), and oxideav-ttf 0.1.9 stopped re-parsing the font for each string it shapes (1.9 ms → 13 µs per new string). Stipple's Cargo.toml asks for them (in a checkout with an older Cargo.lock, run cargo update).
  • Nothing runs out of view. Frames wait while the canvas is scrolled out of view (in a page, or as an iframe in another page) or the tab is hidden: stipple.js holds back requestAnimationFrame and tells the module (stipple_visible), whose frame clock stops instead of falling back to a timer. Back in view, it draws a whole frame and animations go on. An idle app does nothing at all.

The examples on the site, measured in Chrome on an Apple M5 Max (headless, on the real GPU) in a 1280×800 window at a pixel ratio of 2 (a 2560×1504 canvas), driving real input through the DevTools protocol. Work is the time spent in the module per event or frame (build, layout, paint, rasterize and present, or lower and submit on the GPU); latency is from the event's timestamp to the end of the first present after it, median / 95th percentile, and includes waiting for the display's next frame where the answer is animated (a hover highlight fades in). Before: the CPU, the dependencies Rust 1.88 resolved to then, a plain release build.

ExampleFirst frameHover: work p95Hover: latencyClick: latencyTyping: latencyWheel: work p95, latencyAnimation: frame p95
widgetsdemo, before662 ms376 ms353 / 383 ms
widgetsdemo, CPU now124 ms1.6 ms11 / 16 ms
widgetsdemo, GPU now106 ms0.9 ms11 / 15 ms
todo, before81 ms17 / 44 ms2.6 / 3.8 ms
todo, CPU now34 ms1.7 / 5.8 ms1.0 / 1.1 ms
todo, GPU now40 ms0.4 / 1.1 ms0.7 / 0.8 ms
listgestures, before541 ms70 ms9.7 / 23 ms24 / 301 ms425 ms, 408 / 448 ms
listgestures, CPU now61 ms10 ms7.3 / 15 ms4.0 / 4.9 ms21 ms, 43 / 48 ms
listgestures, GPU now47 ms1.1 ms12 / 16 ms0.8 / 1.6 ms0.7 ms, 15 / 32 ms
tabledemo, before984 ms6.5 ms9.4 / 18 ms5.2 / 182 ms2.5 ms, 19 / 37 ms
tabledemo, CPU now59 ms2.0 ms9.7 / 16 ms2.1 / 10 ms1.3 ms, 11 / 27 ms
tabledemo, GPU now52 ms1.1 ms11 / 16 ms1.6 / 2.0 ms0.8 ms, 12 / 27 ms
motiondemo, before107 ms5.3 ms11 / 19 ms7.2 / 11 ms13 ms (1 dropped)
motiondemo, CPU now49 ms2.4 ms11 / 16 ms2.0 / 2.1 ms5.1 ms
motiondemo, GPU now43 ms0.4 ms12 / 18 ms0.5 / 0.9 ms0.7 ms
gamedemo, before198 ms5.2 ms9.3 / 20 ms8.1 / 16 ms10 ms
gamedemo, CPU now106 ms2.5 ms11 / 20 ms7.5 / 15 ms5.4 ms
gamedemo, GPU now78 ms1.1 ms13 / 17 ms7.4 / 15 ms0.7 ms
spritedemo, before46 ms6.2 ms11 / 15 ms6.0 / 7.0 ms6.5 ms
spritedemo, CPU now38 ms4.1 ms12 / 16 ms4.1 / 4.3 ms4.3 ms
spritedemo, GPU now30 ms0.3 ms12 / 16 ms0.4 / 0.6 ms0.3 ms
themegallery, before92 ms0.9 ms8.3 / 15 ms
themegallery, GPU now45 ms0.6 ms13 / 16 ms

(gamedemo answers a click on its next game tick.) No animation dropped a frame after the changes; motiondemo dropped one before. At a pixel ratio of 1 the CPU numbers are about a quarter of these. The benchmarks (tools/bench/run_web.py, built as the site builds) went, on the CPU: theme_switch 267 → 5.1 ms, first_frame_2x 1050 → 10.7 ms, scroll_list 40.8 → 3.1 ms, text_layout_cold 373 → 2.2 ms, startup 446 → 7 ms, and in the page web_theme_switch 290 → 17 ms and web_scroll_list 44 → 17 ms (both now within a frame, which is what they wait for).

Two more things the CPU renderer does now: a floating overlay that stays up (a toast) no longer makes every frame a whole one (the tree diff covers the overlay layers like the rest; widgetsdemo's welcome toast had made each hover repaint the window), and a rectangular clip around content that sits well inside it is left out (it clipped nothing, and cost a mask the size of the repainted area for each primitive under it: a list's clipped rows). What is left on the CPU is fill rate: a wheel step over listgestures repaints the whole list, 2.3 million pixels at a ratio of 2, in about 20 ms.

View this page on GitHub