perf(viewer): mount the viewer shell at idle, before the first file

Closed
LO
19d ago
+682-215

Fixed load floor, step (a) of the load-time hillclimb's warm-runtime lane: the viewer shell and its WebGPU renderer exist before the first file arrives.

Problem (measured on main, untimed, Pop GPU; details in the lane's FLOOR.md)

Until the first open the viewport rendered only the welcome screen. The open itself therefore:

  • swapped the welcome screen for the viewer (a 130-230 ms main-thread "UI reset" before file.read on FZK; 65-80 ms on a second load in the same tab);
  • created the WebGPU device and pipelines in that new Viewport (deviceMs 145-170 alone). A snapshot reopen in a fresh tab waits for it: on Holter, cache.lookup end to cache.snapshotRead start is 372 ms of an idle main thread waiting for the renderer.

Change

  • ViewportContainer renders one tree in every state: the viewer shell (unchanged children) plus, while no model is loaded, the welcome screen as a layer over it (welcome/ViewportWelcomeLayer.tsx, moved out verbatim). The shell keeps its position, so the first open no longer remounts it.
  • welcome/warm-shell.ts: at the first idle period after the welcome screen is up, the shell mounts under the welcome layer, inert and visibility: hidden (laid out, so the canvas has its real size; never painted or focusable). The render runs as a React transition. If a file is opened first, the pending warm-up is cancelled and the open mounts the shell exactly as before.
  • Skipped (main behaviour) when the browser reports < 4 GB deviceMemory, asks to save data, has no usable WebGPU, or with the kill switch perf.warmShell=0 (registered in lib/perf/flags.ts). While the tab is hidden it waits for visibility. The gate lives in lib/warm-runtime-gate.ts for the next warm-up steps.
  • lib/boot-settled.ts exposes __ifc_lite_boot_settled__(): false until this idle work has finished (renderer initialised) or been refused. #9744 makes the load scoreboard wait for it before arming an open, as a user who takes a moment to pick a file would; without it the shell was ready at the arm in only about half the opens.
  • No change to useIfcLoader, the renderer package, embed, CLI or workers. Device loss and recovery are the viewport's existing code, now also reachable before the first load.

Evidence so far (untimed, Pop, ifc-gpu-check, 12-14 GiB scope, interleaved, quiet gate)

Prototype with only this piece vs main (n=3, host load ~10):

mainshell at idle
advanced_model snapshot reopen, interactive15751016
advanced_model snapshot reopen, first frame895349
Holter snapshot reopen, interactive34172888
Holter snapshot reopen, first frame1033645
Holter lookup end -> snapshot read start (renderer wait)37212
advanced_model first reopen, first frame1079561
FZK cold UI reset (loadStart -> file.read)226162

Holter cold at n=3 was not separable from noise (one 13.9 s outlier on the branch side); the timed run below decides it.

Pending before this is handed for review

  • Timed scoreboard A/B on Pop (base main@d45ace6b65 vs this head; 7 fixtures, 4 lanes, 7 interleaved rounds; arm after boot settles via #9744), plus the worst case arm: first-paint (open at first paint, warm-up not run), which must not be slower than main.
  • Boot cost for visitors who never open a file: time to a quiet welcome screen, boot long tasks, idle JS heap / process PSS / VRAM, before vs after.
  • Eager JS bytes vs the ratchet.
  • tests/e2e/warm-shell.e2e.spec.ts (new, viewer-e2e-ci): the renderer exists before the first open under an inert hidden shell, the open keeps that canvas (no remount), perf.warmShell=0 keeps main's behaviour. It fails on main.
  • Full 4-shard viewer suite (fleet), root typecheck, viewer-embed, device-loss and welcome e2e specs, Firefox spot check.

node scripts/pre-handoff.mjs --base d45ace6b65: all gates pass; retained-free viewer skipped locally (no dist), covered by CI.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The viewer can prepare its viewport behind the welcome screen and reuse it when you open a model.
    • Viewport preparation is skipped when data saving is enabled or the device reports less than 4 GB of memory. It pauses while the tab is hidden and can be disabled with ?perf.warmShell=0.
    • The welcome screen supports file selection and drag-and-drop, and displays load errors and WebGPU support information.