perf(viewer): publish parser stores after the geometry tail, newest only
While the geometry tail runs (upload queue drain, then renderer finalize), the viewer now holds the parser worker's store publications and publishes only the newest store once the tail ends. A store that is ready before stream completion, or after the tail ends, is published immediately, as before.
Why
Measurements are from traced, sourcemapped cold loads on main+#9684+#9747 (Pop, quiet host, untimed; used for attribution):
- Finalize: renderer finalize does ~205–235 ms of its own work in every load. It took 555–798 ms in the 4 of 7 loads where the parser's publications landed inside it. The main thread was 100% busy in those windows, so finalize was not slower; it shared the thread.
- Partial store: publishing it (hydrate, store commit, React render of the panels,
search.tier1, render-time derivations such assymbolic-parse-cache-keysandobject-count) cost ~250 ms on BWK and ~500 ms on Holter of main-thread time inside the tail. The full store replaced it a few hundred ms later. On Holter it arrives during the drain and stretched the drain from ~330 ms of renderer work to 886 ms. - Timed figures (scoreboard s5, exclusive admission, 5 rounds): finalize takes 195–245 ms when metadata stays out of it and 518–680 ms when
parser.completelands inside it (Holter 1 of 5, BWK 3 of 5).
Change
metadataPublishGate.ts: hold during the tail, then release only the newest store. A full store that overtakes a held partial is the only one published. A 3 s hold limit means a finalize that never ends (device loss) cannot park metadata.- Large loads only:
METADATA_HOLD_MIN_MB = 32, the loader's existing large-load size (the entity-index deferral). Below it every load publishes at once, as before. With the small-file fast path (#9900), FZK's parser finishes before its tail, so a hold would only delay it. - Loader rule (
loaderHoldsMetadata): hold only a large primary load, after its stream completed, while it is current, during the geometry tail. The tail is queued meshes, streaming fragments, a finalize in progress, or pending instanced shards (geometryTail.ts).- A held full-store publication that throws still fails the metadata promise.
- A load that goes stale (superseded or cancelled) during the hold is released at the next poll, and the loader's publish handlers write nothing for it.
- A model closed during the hold: closing a model does not cancel its load. Without a guard, a store held through the tail would have been written to the active store after the close, bringing back a closed model's metadata; on main that store had already been published before the close. So a held store is not written to a primary model that is no longer in the store (
heldStoreTargetsClosedModel). The metadata promise still settles, as it did on arrival. An unheld store publishes exactly as on main. - Milestones:
parser.spatialReadyandparser.completeare stamped when the store ARRIVES, held or not.- The new
parser.publishedmarks the full store's publication: the release for a held store, the same moment asparser.completeotherwise.
- Size budget:
geometryTail.tsholds the tail predicate, andfillCalculatedStoreyHeights(localParsingUtils.ts) folds the storey-height fill that the two publish handlers each repeated.useIfcLoader.tsis 2,170 lines, inside its budget.
Which reported numbers the milestone change affects
-
Before this revision, the gate stamped
parser.completeandparser.spatialReadyat publication. So on held loads, the branch side of the timed slots below reported the release time under those names: -
Interactive is not affected. It is max(geometry finalized, metadata ready, first frame after the store settles), and the settled frame always follows the release.
-
What does change on held loads:
- the probe's metadata-ready column;
- field telemetry's
metadata_complete_msandspatial_ready_ms, which now mean arrival.
The publication time is
parser.published.
Limits
- Size is
file.size, the bytes picked. A small.ifczipthat unpacks to a large model is never held. Federated adds, cache hits and server loads are never held either. - In a hidden tab the upload drain is paced by animation frames, which stop. So a large load in a background tab keeps the tail busy and waits for the 3 s hold limit before its store is published.
Trade-off (measured on the shipped code; the decision is pending, so this PR is not labelled)
On a large cold load the hierarchy panel's first rows appear later: when the load becomes interactive, instead of ~680 ms before it. The load itself finishes sooner. The delay is this PR's: the gate holds the partial store the panel draws from. #9855 does not touch the panel.
Slot p2, job 981dfd0c, exclusive admission. Base 000532b2cc (main+#9684+#9747) vs pair 9053a6590b (+ #9830 dba67fa0fb + #9855 462c14fc59, the shipped code before the rebase). 5 clean rounds; no sample overlaps the foreign-process window (01:44:50-01:45:33 UTC).
| Holter (177 MB) | base | pair | |
|---|---|---|---|
| cold, interactive | 3,663 ms | 3,353 ms | +8.5%, PASS (bar 6.3%) |
| reopen (warm1), interactive | 1,826 ms | 1,542 ms | +15.6%, PASS |
| reopen (warm), interactive | 1,789 ms | 1,547 ms | +13.6%, PASS |
| first hierarchy rows, painted (2 rounds) | 3,037 / 3,040 ms | 3,478 / 3,510 ms | ~455 ms later |
- Peak memory, UI quiet and first geometry: no significant difference.
- Data-store digests: identical on all 7 scoreboard fixtures. Settled frame with overlays: pixel-identical (
8cad59d75bd80940, 2 of 2 reps per side). - BWK first hierarchy rows: unchanged (3,012/3,067 → 2,951/3,055). FZK grid/annotation fixture: unchanged.
- First annotation overlay: not delayed (FZK grid 920/950 → 930/928 ms).
- BWK cold: rerunning as a complete unit. This slot's BWK samples overlapped a foreign-process window and a watchdog pass.
Options under consideration:
- land the pair as is;
- a variant of this gate that lets the first partial store (or only what the hierarchy panel needs) through;
- land #9855 alone and keep this PR back. #9855 is self-contained, and its reopen gain does not depend on this gate: reopens are cache hits and never pass the gate.
Timed results
- On its own: not significant. Exclusive slot, job bfb99722, base
000532b2cc= main+#9684+#9747, 4 fixtures, cold plus both reopens, 5 rounds, memory pass.- Holter cold interactive 3,825 → 3,625 ms is +5.2%, against a bar of 6.3% (twice the noise floor).
- BWK 3,390 → 3,391; advanced_model 1,499 → 1,463; FZK 572 → 579. No cell regresses, peak memory included.
- Geometry finishes 625 ms earlier on Holter, 481 ms on BWK and 201 ms on advanced_model, and finalize is back to ~220 ms. But the held store's commit then runs after the tail and becomes the end of the load. Removing that work is #9855's job.
- As a pair with #9855 (pre-review code): combined slot 0d633001. Holter cold 3,879 → 3,505 ms (+9.6%, bar 6.3%), warm1 1,828 → 1,618, warm 1,843 → 1,571, all PASS; advanced_model and FZK not significant; BWK inconclusive; no regressing cell.
- Pending (review-fixed heads, rebased onto main
22a1b40e84, head5b69fd2246):- the pair arm rebuilt with smoke check, data-store digest (7 fixtures) and pixel check;
- one slot: Holter cold plus both reopens, BWK cold, and the hierarchy-rows and first-overlay delays;
- the three-arm #9900 proof that the 32 MB rule keeps FZK, duplex and Office_A neutral.
- Landing: #9830 first, then #9855 retargeted onto main.
Tests
metadataPublishGate.test.ts(11 cases), loaded at runtime with every export the loader uses asserted:- coalescing, pass-through and the hold limit;
- the size boundary;
- arrival callbacks and the held flag;
- the loader rule (primary only, after stream complete, not stale, size; the scene is not queried for a load that cannot be held);
- stale during the hold;
- a model closed during the hold.
- Local runs on
dba67fa0fb:- viewer typecheck clean;
- module-size check passes (
useIfcLoader.ts2,170 lines); - the 70 test files that touch the loader, the parser milestones or
localParsingUtils: 680 pass, 1 fail, 4 skipped. - The failure is
gaussian-startup.test.ts"Dependency outside repository: …history.ts -> @ifc-lite/sdk/review". It comes from the local setup: dependencies are linked from another checkout, so the import walk resolves@ifc-lite/sdkoutside the repository. This change touches no imports. PR CI runs it on a clean checkout.
This PR stays unqueued until those are in.
🤖 Generated with Claude Code