perf(viewer): non-load work waits for the settled scene
What
Step 1 of L1 (design: cold-finalize/L1-DESIGN.md, campaign scratch). On a Holter cold load the main thread is 96–100% busy from parser.complete to the end of the load. In that post-stream window, two pieces of work serve nothing that "interactive" needs.
Holter cold, main@cb641084ba, traced, ms of main-thread self time:
| work | Holter | advanced_model | what it serves |
|---|---|---|---|
| cache-write encode | ~375: buffer-utils 107, TextEncoder 127, appearance provenance 50, geometry chunks, strings, entity index | ~150 | the next open |
| placed spatial index: instanced materialisation + builder + BVH | ~290: materialisation 166, builder 61, BVH 63 | ~100 | SDK and server spatial queries (not picking) |
Both started at load.finalize, which comes before the renderer's drain and finalize, so they competed with those for the main thread.
The change makes both wait for one shared scene-settled signal. It is the predicate #9623 introduced for the georeference minimap, factored into apps/viewer/src/lib/scene-settled.ts: the store has left its loading state, nothing streams or waits to upload, and the renderer has no queued meshes, fragments or finalize in flight.
- Placement index sync (
spatial-index.ts): while the scene is unsettled, its debounce timer keeps the models pending and looks again. The existing generation guards still drop superseded builds. - Cache write, primary and federated (
useIfcLoader.ts): it starts after settle.whenSceneSettled(isCurrent)resolvesfalsewhen a newer load supersedes this one, or after 120 s if a failed finalize never settles; the write is then dropped. These are the conditions the rejected NEW-5/#9622 attempt asked for: a real readiness signal, no cloned geometry, and supersession dropping the work. Source compaction still runs after the write. BinaryCacheWriter.write({ yieldBetweenSections })(cache package, opt-in, written bytes unchanged): returns to the event loop after each section, so a write made while the page is interactive runs as short tasks.- The minimap gate (
use-location-map-ready.ts) uses the shared predicate.
No geometry, GPU or output change.
Interaction with #9628 (merged). #9628 moved pendingInstancedShards out of the store. This branch has merged it: the predicate calls hasPendingInstancedShards() from @/store/instancedShardQueue, so shards still in that queue keep the scene unsettled.
Deterministic checks (fail on main)
spatial-index.test.ts: "builds no placed index while the scene is still draining or finalizing, then builds it once settled". The model is load-complete and its scene is finalizing. Across two debounce periods there is no index and no materialisation; when the finalize ends, the index publishes.useIfcLoader.cacheAfterSettle.real-ifc.test.tsx: a real C20 (10.8 MB) cold load through the actual loader and WASM, with the renderer still finalizing. No cache entry appears for 10 s; once the finalize ends, it is written.scene-settled.test.ts: every condition, supersession and the timeout.cache.test.ts: withyieldBetweenSections, at least 6 macrotasks run during the write, and the bytes match the non-yielding write.
Timed verdict (exclusive A/B)
Base main + #9684 (3fb357d873), branch main + #9684 + this PR (000532b2cc), both on main@12fd328582, each built in its own checkout; harness = main's scripts/perf (#9607); 4 lanes × 5 interleaved rounds + memory pass; verdict = gain ≥ 2× the noise floor (max of the stage-0 A/A floor and the run's own).
Which run each verdict comes from. Slot s5 (benchmark job 6468479a, 2026-11-12 05:44–06:25 UTC) was contaminated in its first minutes: another lane ran two builds outside benchmark admission from 05:41 to 05:48 UTC. All 31 samples of round 0 of the first group (FZK, ISSUE_129, advanced_model, schependomlaan) fall in that window and carry the harness's underLoad flag. Those four fixtures' s5 cells are discarded; their verdict comes from a complete five-round rerun, slot s6 (job 890899e7, 06:51–07:08 UTC, 0 of 160 samples under load). Holter, skolebygg and BWK ran in s5 after 06:02 UTC with 0 samples under load; their verdict comes from s5.
| fixture | run | browser-cold interactive: base → this | gain | 2× floor | verdict |
|---|---|---|---|---|---|
| Holter | s5 | 4,549 → 3,754 ms | +17.5% | 6.3% | PASS gain |
| BWK | s5 | 3,622 → 3,328 ms | +8.1% | 5.4% | PASS gain |
| skolebygg | s5 | 2,683 → 2,435 | +9.3% | 9.9% | no significant difference |
| advanced_model | s6 | 1,753 → 1,515 ms | +13.6% | 10.9% | PASS gain |
| schependomlaan | s6 | 1,161 → 1,069 | +7.9% | 11.5% | no significant difference |
| ISSUE_129 | s6 | 2,735 → 2,685 | +1.8% | 8.3% | no significant difference |
| FZK | s6 | 559 → 580 | −3.8% | 21.7% | no significant difference |
- Holter browser-cold UI quiet 5,124 → 4,399 ms (+14.1%, PASS).
- No regression in any cell of either run: every fixture × lane (native, browser-cold, first reopen, snapshot reopen) × metric (interactive, first geometry, UI quiet, peak memory) is a gain or no significant difference.
- Output identical: browser-cold element hashes (flat + instanced) identical in all 10 samples of every fixture. Reopen samples carry no element hashes in this harness (unverifiable there, as on base).
- Reports:
~/.t3/scratch/2026-11-10-ifc-load-hillclimb/cold-finalize/l1/runs/s5-9747/report.md(Holter, skolebygg, BWK) and…/runs/s6-9747-g1/report.md(FZK, ISSUE_129, advanced_model, schependomlaan).
Status
- focused fleet runs, branch and RED: see below; on
d5259aea76(job1bdbbb8d) cache ok, viewer 263/263 - Tests run on this exact head (
d5259aea76):@ifc-lite/cachefull suite 249/249 (28 files, run directly on Pop, no GPU); fleet job1bdbbb8don Pop with real fixtures and WASM built: the viewer selection covering everything this changes, 263/263 (scene-settled,model-placement/spatial-index,cacheAfterSettle,LocationMap,coordinateCache,sceneSnapshot*,coldScene*,useIfcCache,useIfcLoader), including both L1 tests and the real-C20 cache-after-settle test. CI Typecheck green on this head. - Full four-shard viewer suite on
d5259aea76(fleet jobcd0d30b6, PC): shards 1–3 green; shard 0 had 1 failure,useModelRotationSync.test.ts#4890 (scene?.hasQueuedMeshes is not a functioninisSceneSettled, from a scene test double). Fixed in6beac84a86(optional calls; production scenes implement all three). That test fails without the fix and passes with it;useModelRotationSync+scene-settled+model-placement/spatial-index39/39 on6beac84a86. The merge queue runs the full suite on the final head. - exclusive timed A/B (above)
- review threads: 0 open
Focused tests on the fleet (real fixtures, wasm built)
| head | cache | viewer focused |
|---|---|---|
82476f975a (= 848559595d but for a doc comment) | 30/30 | 56/56, including the real-C20 cache-after-settle test and the placed-index L1 test |
| same tests with the fix reverted (throwaway copy) | 29/30 (the yield test fails) | 51/53 (both L1 tests fail) |
🤖 Generated with Claude Code