DEV Community

Daisuke Mino
Daisuke Mino

Posted on Originally published at minodisk.dev

Owning the Path from Key Press to Screen

Handpic is a culling app for RAW files: you page through what you shot, give stars, reject the rest, and the judgments go into metadata files saved next to the RAW files (XMP or DxO PhotoLab format). It reads only the JPEG previews embedded in the RAW files, never develops anything, and never writes to the RAW files themselves.

It started in September 2026 as a Tauri 2 app (Rust backend, TypeScript UI in WebView2). In November I rewrote the whole UI in GPUI, Zed's GPU-rendered UI framework, and deleted the Tauri app.

Developing apps make you wait every time you move to the next photo. Handpic exists partly to avoid that, so one number matters more than anything else in it: the time from pressing → to the next photo on screen.

In Tauri, getting the JPEG into the WebView, decoding it and drawing it all happened on the WebView's side, out of my reach. Moving to GPUI made the whole path from key press to screen my own code, so I could decode only what is needed, drop the copy, and draw ahead of background work. In exchange, things I never had to think about, like uploading textures to the GPU, became mine to handle too. This post goes through them one by one.

Result

Time from the key press to the photo on screen, median of three runs, in ms:

Tauri GPUI GPUI faster by
ARW 1616x1080, p50 45.20 33.63 11.57 (−26%)
ARW 1616x1080, p95 69.08 41.46 27.62 (−40%)
RAF 4416x2944, p50 130.40 61.28 69.12 (−53%)
RAF 4416x2944, p95 145.94 73.09 72.85 (−50%)

The sizes are those of the JPEG preview embedded in each RAW file. At 59 Hz, the gain is about 0.7 of a frame on ARW and about 4.1 frames on RAF.

How I measured

An app's own clock can't tell when a photo is actually on screen, so I built an external ruler, latprobe. It presses → with SendInput and records the time, then watches the screen through DXGI Desktop Duplication until a 64x64 patch in the center changes and settles. The end point is the LastPresentTime of that frame: when DWM presented it. Keyboard latency and the panel's scanout are not included, and the results move in steps of the 59 Hz display's frame, about 16.9 ms.

Absolute numbers shift by several milliseconds depending on when they are measured, so the two apps were measured back to back, alternating: per folder, one warm-up run each, then three runs of 60 presses about a second apart, with prefetching off in both and a 1600x1000 window. Runs during which CPU load went over 15% or a compiler started were thrown away and redone. The machine: Windows 11, i7-13700, RTX 4060 Ti, 32 GB, a 5120x1440 display at 59 Hz, photos on a SATA SSD, WebView2 157.

Where the time goes

Splitting each press at the moment the image finished drawing (p50 / p95, ms):

Key → drawn Drawn → screen
ARW Tauri 17.90 / 26.30 26.73 / 42.88
ARW GPUI 8.03 / 9.83 25.93 / 31.80
RAF Tauri 89.50 / 105.30 37.06 / 46.88
RAF GPUI 35.74 / 44.55 25.35 / 32.45

For Tauri, "drawn" is when the canvas drawImage call returns. With an image as large as the RAF preview, drawImage only records the draw; the actual rasterization (about 22.5 ms) runs inside the next canvas operation, so it falls on the "drawn → screen" side. For GPUI it is derived from the app's stamps (the stamp after Present, minus the vsync wait and Present itself). Each column is a median of its own, so the columns don't add up exactly to the totals above.

Nearly all of the gain is before drawing. The next three sections are what made that part shorter; the last one is about the part after drawing.

1. Decode only the pixels the screen shows

On RAF, decoding and drawing the JPEG took the most time. In Tauri, decoding with createImageBitmap took 55.2 ms at p50, and drawing onto the canvas took about another 22.5 ms. In GPUI the same RAF decode takes about 34 ms and the paint 0.71 ms: about 78 ms became about 35 ms.

GPUI decodes with mozjpeg on a background thread. The change of decoder alone did not get there: RAF decode was 47.3 ms, and on ARW it was actually slower (6.0 ms in Tauri, 9.2 ms in GPUI at p50). The rest came from fixing a problem the first on-screen measurement exposed.

GPUI, on the first paint of a new image, uploads the whole decoded texture to the GPU. A 4416x2944 preview is 52 MB. With about a second between page turns, the GPU had dropped to a low power state and PCIe to Gen1 x8, so the upload took about 33 ms and missed two DWM compositions. Present doesn't block, so the app's own clock never saw it: the frame reached the screen 14 ms after the app's stamp on ARW, whose 7 MB texture uploads in about 5 ms, and 48 ms after it on RAF.

The fix was to stop decoding pixels nobody sees. The fit view now decodes the preview at the smallest of mozjpeg's n/8 scales that still covers the canvas in device pixels: 3/8 for RAF in a 1600x1000 window, 1656x1104, about 7 MB. Layout and overlays use the source size instead of the texture's, and the 1:1 view still reads the full image. Measured before and after, back to back, on screen (p50 / p95, ms):

Before After
ARW 1616x1080 36.63 / 49.92 37.44 / 47.56
RAF 4416x2944 112.60 / 137.87 64.94 / 76.26

ARW didn't change beyond noise. On RAF, decode went from 49 to 34 ms and paint from 3.55 to 0.71 ms at p50; the remaining ~32 ms is the upload no longer stalling.

One more thing to check here: mozjpeg-sys quietly falls back to non-SIMD when NASM is missing. RAF decode went from 46 ms to 99 ms with no visible warning, so the build script now fails instead.

2. Stop copying the image across a process boundary

In the Tauri app, a page turn went like this:

  1. read — Rust reads the embedded JPEG from the RAW file
  2. ipc — the JPEG bytes are sent across the Tauri IPC into the WebView
  3. post / worker — handed to a Web Worker
  4. decode — createImageBitmap
  5. draw — drawn onto a <canvas>

Steps 2 and 3 only move bytes, yet at p50 they took 4.4 ms on a 1616x1080 ARW and 29.4 ms on a 4416x2944 RAF preview, a JPEG of 1.3–5.5 MiB. Of the RAF's 29.4 ms, 28.0 ms was the IPC copy itself. No amount of tuning inside Tauri removes that: the bytes have to get into the WebView somehow.

In GPUI there is one process. A background thread decodes the JPEG, and the decoded image goes to the UI thread as an Arc: 0.02 ms on ARW, 0.42 ms on RAF.

3. Put the page turn ahead of background work

Handpic does heavy background work while you page: a first scan pass that fills thumbnails and the index, and a second pass that runs face detection, focus and eye-sharpness models on every file.

In the Tauri app, page turns on RAF got slower while the second pass ran: from 135.33 to 153.80 ms at p50 and from 153.50 to 178.35 ms at p95, on screen. ARW barely changed. The app paused the scan's reads while a preview was being read, but the decode and the draw ran inside WebView2's own processes, and drawImage returning is not the moment the frame reaches the screen. So the pause could not cover the second half of the page turn.

In GPUI the whole path from read to paint is my code in one process, so I can order it explicitly:

  • One preview request in flight at a time, so holding → never queues stale decodes. A result for a file that is no longer current is still drawn, then the current file is requested and the files in between are skipped.
  • The preview pauses the scan before the read and releases it only after its image has been painted. While the pause is held, the second-pass workers yield at every stage boundary, so the read, the decode, the orientation and the paint get the cores.
  • The second pass runs on an eighth of the cores.

Page-turn time on screen, measured back to back (p50 / p95, ms). This was a different run from the result table, so even the values without pass 2 differ slightly.

Without pass 2 During pass 2
ARW Tauri 52.50 / 76.20 48.81 / 71.77
ARW GPUI 37.81 / 46.60 33.09 / 40.93
RAF Tauri 135.33 / 153.50 153.80 / 178.35
RAF GPUI 65.82 / 80.18 64.09 / 84.29

In GPUI, the p50 does not get slower while the second pass runs, on either ARW or RAF.

What's left: one frame after drawing

The part after drawing still takes 25.93 ms on ARW and 25.35 ms on RAF in GPUI. GPUI on Windows draws only when its vsync thread, waiting on DwmFlush, invalidates the window, so a frame that is ready waits for the next tick (7.5–10 ms at p50). It then presents just after that tick, so DWM composites it at the following one, about 15 ms later.

I tried forcing an immediate redraw from the app with a direct Win32 call. On screen, the p50 went from 33.51 to 25.10 ms on ARW and from 60.99 to 56.14 ms on RAF, but only 34–47% of presses gained a frame, and it relied on GPUI internals outside its public API. I reverted it. The right fix belongs in GPUI itself, and I haven't proposed it there yet.

Handpic is open source; see the repository for building it from source.

Top comments (0)