perf(viewer): after-load jobs wait for the load window (stacked on #9782 and #9855)
Stacked on #9782 (the after-load queue) and #9855 (the load window). This PR's own change is the top two commits; until both land, the diff against main also shows theirs.
CI blocker in #9855. #9855 at 65a907bd83 declares let viewerLoadWindow and export function viewerLoadWindow() in one module, which is a SyntaxError (Identifier 'viewerLoadWindow' has already been declared), so loadWindow.ts does not load. I reported it to that lane with the fix. My local runs used a throwaway copy with only that rename applied.
Why
On a Holter snapshot reopen the after-load queue starts its jobs when the model's record reads complete. The record turns complete at the finalize publish, before settleLoadUi and the interactive frame. Measured in exclusive slot 5b25cfc1 (untimed probe, 3 reps): the overlay-parse worker request lands 276–500 ms before interactive on #9782, and 369–419 ms before it on main.
A sourcemapped trace of a Holter snapshot reopen (main 52c82a099d + #9782 + #9785; traced, so ratios only) shows the 412 ms between metadata ready (1,192) and the store settling (1,604). The main thread is busy for all of it, in one synchronous React render and commit set off by the store publish:
| work | ms |
|---|---|
| drawing-markup restore | 96 |
| shaped-object count (status bar, metadata panel) | 77 |
| overlay parse request (source handed to the overlay worker) | 68 |
| symbolic spatial keys | 58 |
| entity ownership | 15 |
| cache relationships | 12.5 |
| viewport summary | 11 |
| React | 29 |
| GC | 20 |
About 325 ms of that is what #9855 holds behind its window. This PR applies the same rule to the after-load queue, so none of its jobs (snapshot write, overlay parse, source compaction, tier-1 search) can start in that stretch. That includes paths #9855 does not gate.
Change
afterLoadReady(state, modelId)=modelLoadSettled(state, modelId) && !viewerLoadWindow().isOpen(): one definition of "the load is over", #9855's. A closed window means the frame showing the settled store has painted.- The queue re-checks on store, shard and window changes. The fallback used when the queue chunk does not load follows the same rule.
- The symbolic hook's immediate re-parse of an already parsed store uses the same predicate.
- Behaviour change: each job waits for ITS model's hold,
viewerLoadWindow().isHeld(modelId)(#9855, on main), not the global window. A model that had settled when another model's load began is not held. In a multi-file open each model is released when the loader ends that model's load and its frame has painted. A load flag that never clears is released by the window's store-busy limit. The 3 s own-hold cap this PR had as a safety net is removed (e21cd80320): the window now covers both cases. The single-store mode keeps the whole window. - New in
afterLoad.test.ts:- a model whose record is already complete gets no job while the store still loads;
- another model's load does not hold a model that had settled when it began;
- in a multi-file open the earlier model's job runs at its own load end (G1);
- a load flag that never clears is released by the window's limit (G2);
- a model removed while held is dropped.
- With the global gate put back, the per-model tests fail.
- Per-model contract in
afterLoadIdle.test.ts('a settled model's job runs while another model loads') anduseSymbolicAnnotations.afterLoad.test.tsx(A parses while B loads; after an edit A re-parses at once and reuses the source parse).
Timing
Not timed yet, on purpose. The combined #9830 + #9855 slot first shows how much of the 325 ms the window removes on Holter's reopens. This PR is then timed against that base.
Focused tests on 7fbd809e2b
Fleet job on pop-os, node v24.22.0:
- cache vitest: 29 files, 256 pass / 1 skip;
- viewer: the after-load queue, snapshot write/load, chunk inflater, cache hit and loader, search index, symbolic overlays and parse cache, overlay-parse, drawing markup restore, grid overlay; 825 pass / 0 fail / 6 skip.
An earlier run on c7e2d95347 (PC) failed "runs at the cap". The cap timer could fire before the clock showed the cap, and nothing re-checked. Fixed in 7fbd809e2b, with a test that uses an injected clock.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
New Features
- Compressed geometry in cached models can now be inflated using background workers, with main-thread fallback if workers are unavailable or fail.
- Search indexing, symbolic overlays, metadata, and element counts now update after model loading settles, helping avoid incomplete results while data is streaming.
- Previously displayed overlay results remain visible while updated results are being prepared.
- Background post-load work is coordinated per model and canceled if that model is removed or replaced.
-
Bug Fixes
- Loading one model no longer delays updates or counts for models that have already settled.
- Search indexes refresh when a model’s underlying data changes.