perf(viewer): small-file fast path, spare parser and geometry workers prepared at idle
What
A small .ifc file now opens without the set-up a 200 MB file needs. Two spare workers are prepared while the page is idle:
- Spare parser worker. Its bundle is loaded, compiled and evaluated, and one warm parse of the shipped
hello-wall.ifchas run. That parse instantiates the engine through the worker's normal path.parser.worker.tsis unchanged. The next parse of any size takes it (WorkerParser, only when no customworkerUrlis set). On main, starting the parser worker accounts for most of FZK's metadata time: 282 ms of bundle compile plus 105 ms of evaluation, against a 39 ms parse. - Spare fast-path geometry worker (
workers/fast-geometry.worker.ts). The engine, and the pool's shared engine module, are compiled and warmed on two shipped samples at idle. The pick hands it theFilebefore the interface reset. It makes the sameprocessAdaptivecall the loader makes (hooks/ingest/adaptiveGeometryOptions.ts, shared by both): the single-session branch below 2 MiB, and the worker pool with GPU instancing from 2 MiB up. So it emits the same events, including instanced shards,unitRefusedandworkerMemory, streamed back one by one. What it saves is the wait: the worker boot, the engine compile and the interface reset.
The load uses that run only if it meshes with exactly the settings the load would use now (GeometryProcessor.meshingSettings(), compared field by field) and the bytes it read are the file's own (a ZIP named .ifc is unwrapped by the loader, so its run is refused; the worker also checks the STEP header). In every other case the run is cancelled and the normal pipeline runs with the bytes the load already holds: a settings mismatch, a worker error or no first event within 5 s, a federated load, or a load that never reaches IFC geometry. After the first event a failure fails the load like the normal pipeline does.
Eligible: a primary load, the exact kernel, not a retry, *.ifc, larger than 0 and below 10 MiB (under 10,485,760 bytes: the uncached tier; a file of that size or more takes the cache path). Everything else is unchanged.
Shared pick hook (hooks/ingest/pickStart.ts)
This is the single place a load may start work before its reset. loadFile calls runPickStart(ctx) once: after it has claimed its session, after the federated cold-tier drain, and before resetViewerState.
- Starters run synchronously, in registration order, and must not block. A throwing starter is logged and the others still run.
- There is no
await: the reset runs in the same task as the pick.
The reopen pre-pixel lane will move #9825 onto it. In useIfcLoader.ts this PR changes only:
- that call, and
- the geometry stage:
claimFastGeometry(file, processor.meshingSettings(), claim),waitForEntityIndexoff when a run was claimed, andfastRunpassed toopenGeometryEvents.
Settled scene: a stream the viewport has not finalized is not settled (lib/scene-settled.ts, useGeometryStreaming.ts)
The gap. isSceneSettled() read true between the store's stream end and the viewport's finalize when the meshes went straight into batches instead of through the queue: nothing queued, no fragment, no finalize running yet. Consumers that wait for a settled scene could start before the final scene:
- the query index;
- the location map;
- the cache entry and the cold scene capture (these never run below 10 MiB, so not on the fast path).
The scoreboard lane's recheck (#10012) found it on a fast-path reopen.
The fix. useGeometryStreaming registers a probe that isSceneSettled() reads. A stream the viewport has seen, or a finalize it has scheduled, keeps the scene unsettled until that finalize ends.
- It only applies with a GPU device: nothing finalizes without one.
- It is cleared on unmount.
Main has the same gap. Loads that do not stream through the queue happen on main today. In untimed samples (main and pair-base sides):
- every load of a 1,756-byte single-extrusion file: 0 of 15 streamed;
- the generated instanced-only file: 0 of 6;
- FZK occasionally: 1 of 72.
So the fix matters beyond the fast path. With the parser spare alone it happens more often (duplex 4 of 5, FZK 1 of 5): the parse ends earlier, so the stream and its end fall into one frame. The scoreboard lane's 690 stored timed samples had no such load, because none was of a tiny or instanced-only file.
What could start early before the fix. From 20 untimed FZK traces of the pre-fix head:
- the window, from
loadingoff to finalize end, was 18-93 ms on loads that did not stream; - the query index started 115-201 ms after finalize in all 20;
- the location map checks first 100 ms after
loadingclears.
So nothing was observed starting early, but both could under load.
Test. useGeometryStreaming.settled.test.tsx covers:
- a fast-path burst: unsettled from the stream's end until finalize ends;
- an ordinary stream, as before;
- a federated add: settled at once;
- no GPU device: never stuck;
- unmount: nothing left pending;
- an adopted reopen, with and without a stream, with and without a GPU device.
With the fix reverted, two cases fail: the burst, and an ordinary stream whose queue had already drained.
Holter: the post-finalize frame (checked, not caused by this PR)
The scoreboard sizing saw the next presented frame 165-168 ms after the mark on 2 of 3 #9900 Holter cold samples, against 1 of 9 on main. Untimed traces show why, on the sizing's own builds and on this head:
- One ~160-204 ms React render of the properties/metadata panels runs 17-91 ms after finalize on every arm, main included. Most of it is symbolic-parse cache keys, object counts and model stats.
- It is fired by a 0 ms timeout from a
bottom-strip-header-slotanimation-frame callback. - When it runs before the finalize frame is presented, that frame waits for it.
- Nothing from the fast path runs in that window: no spare work, idle worker threads, only a 0.03 ms store listener.
The render is handed to the metadata lane. The confirmation run reports Holter and BWK cold under both marks, with the stall share per side.
The idle cost, and the decision: on by default
Every visitor pays this, including one who never opens a file:
- about 62 MiB more process memory while idle (timed: PSS 621 → 683 MiB, read 60 s after boot);
- about 0.6-0.8 s of worker CPU once at idle, plus the same again after each load to refill the spares.
In return, small files are on screen sooner. Untimed, corrected (see Evidence): on FZK the fast path's first drawn frame has a median of 555 ms, against main's interactive mark of 787-1,614 ms in the same run (main sampled at higher host load). On larger files (Holter, BWK) the parser spare has no measurable effect in the timed run.
Timed, on top of #9855: FZK cold 541 → 404 ms (+25%), with no regressing cell elsewhere. See the timed A/B below.
Decision: the fast path ships on by default. The user was asked about the +62 MiB idle cost and did not object. The kill switch stays: ?perf.fastPath=0 turns everything off for a session, and the registry default (fastPath in lib/perf/flags.ts) turns it off for everyone in one line. The cost will drop once #9838-#9841 are on main: the parser spare then compiles a 1.4 MB bundle instead of 4.6 MB. I will re-measure on top of them.
Cost and bounds (what a visitor who never opens a file pays)
-
Memory. Untimed, prototype, n=2: idle PSS +54 MiB, all in the renderer process. JS heaps +20 MiB (the parser worker's heap is 17.8). The fast-path worker's wasm is 12 MiB. VRAM is unchanged, because no GPU state is created before a file.
-
CPU at idle. 340-430 ms of geometry warm-up and 240-330 ms of parser spawn plus warm parse, all in workers.
-
Gates. Nothing is prepared:
- while a load runs;
- while the tab is hidden;
- when the browser reports under 4 GB of device memory or asks to save data;
- when
crossOriginIsolatedis unavailable (parser spare only); - with
?perf.fastPath=0.
Every await in the preparation re-checks for a running load.
-
One spare of each kind at most. A load consumes them, and they are refilled only after the load ends. A second load gets the same benefit for the same idle memory.
-
Release. Both spares are released after 5 min hidden or 20 min without input; the next visible input re-arms them at idle. Browsers expose no memory-pressure signal to pages, so nothing else is watched.
-
Eager JS. The runtime is its own chunk (
lib/fast-path/startFastPath.ts), loaded with a dynamic import at idle. The entry chunk gains only the pick hook, the claim seam, and a few lines inwasm-prewarm.tsand the flag registry. -
Embed (
apps/viewer-embed) has its own entry and never starts the runtime. There the hook has no registrants, the claim returnsnulland no spare exists, so its behaviour is unchanged. The CLI and tests are unaffected.
Evidence
Correction: the earlier fast-path "interactive" figures were partly measured before first paint
The scoreboard probe's interactive mark waits for the GPU drain only once the drain has started. A fast-path run arrives in one burst and skips the streaming queue, so whether the mark waits for it depends on when the probe's poll lands. A per-frame picture check (untimed, Pop, FZK, build 40cc9dee5a, which has this PR's geometry path) found:
- Mode A (2/8): the mark was recorded before any frame was drawn. At 434 and 456 ms the renderer had drawn nothing and the drain had not started.
scene.finalizeended at 504 and 514 ms. - Mode B (6/8): the mark was recorded at about the finalize end.
- Main (4/4) streams, so its mark always comes after finalize. Its figures are unaffected.
So the prototype table and the "602 → 363 ms" headline that were here earlier are superseded: they mixed both modes. The corrected mark is max(recorded mark, finalize end, first frame with draws):
| FZK cold, untimed, same run | n | recorded mark, median [range] | corrected mark, median [range] | first drawn frame, median |
|---|---|---|---|---|
| this PR | 8 | 562 [434-809] | 562 [504-991] | 555 |
| main | 4 | 1,221 [787-1,615] | 1,221 [787-1,615] |
Main's samples here ran at host load 8-10 against 6-8 for the PR, so the gap is not a measurement of the gain. The timed slots report FZK with the corrected mark, split by mode. The probe itself is being fixed in the scoreboard lane.
Untimed prototype (Pop, fleet --gpu, n=5, FZK cold interactive, median [range]): superseded, see the correction above
| run (host load) | main | spare parser only | + fast geometry, worker-first | + generic warm-ups |
|---|---|---|---|---|
| fast6 (3.7-4.9) | 602 [584-631] | 363 [352-434] | ||
| fast4 (5.6-11.5) | 761 [639-1125] | 482 [447-685] | 421 [372-497] | |
| fast3 (4-11) | 702 | 639 | 599 |
- Geometry side (warm arm): the worker is done at about 115-147 ms and stream complete is at about 173 ms.
- Parser side:
parser.completeabout 311 ms, against 554-682 ms on main. - Identity: element signatures equal main in every sample: FZK 30/30, duplex and Office_A 32/32.
- Small fixtures (n=2): duplex 676/746 → 456/749 ms; Office_A 807/808 → 578/898 ms.
Differences from the measured prototype:
- The geometry warm-up uses the shipped
building-architecture.ifcinstead of a synthetic sample, so no new asset ships. - Search tier-1 deferral is left out.
- The timed run below measures exactly this head.
Timed A/B (exclusive benchmark slots on Pop, 2026-11-13, scoreboard)
The pair measures this PR as it would land after #9855:
Before the slots, the extended identity check matched on 7 fixtures: FZK, Office_A, duplex, a generated instanced file, advanced_model, Holter and BWK.
Interactive ms, median [range]:
| fixture | lane | n | base | branch | gain | 2x floor | verdict | output |
|---|---|---|---|---|---|---|---|---|
| FZK | cold | 6 | 541 [501-546] | 404 [361-444] | +25.2% | 21.7% | gain | identical 12/12 |
| FZK | warm1 (uncached reopen) | 6 | 510 | 391 | +23.4% | 11.1% | gain | identical |
| FZK | warm (uncached reopen) | 6 | 498 | 392 | +21.3% | 9.6% | gain | identical |
| advanced_model | cold | 5 | 1,416 | 1,378 | +2.7% | 9.5% | no significant difference | identical |
| advanced_model | warm1 / warm (snapshot) | 5 | 819 / 752 | 829 / 761 | -1.2% / -1.2% | 5.8% / 17.6% | no significant difference | snapshot samples carry no element hashes |
| Holter | cold | 5 | 3,426 | 3,384 | +1.2% | 6.3% | no significant difference | identical |
| Holter | warm1 / warm (snapshot) | 5 | 1,487 / 1,485 | 1,515 / 1,475 | -1.9% / +0.7% | 5.6% / 6.8% | no significant difference | as above |
| BWK | cold | 5 | 3,266 | 3,245 | +0.6% | 6.6% | no significant difference | identical |
| BWK | warm1 / warm (snapshot) | 5 | 1,451 / 1,431 | 1,451 / 1,435 | 0.0% / -0.3% | 4.3% / 10.2% | no significant difference | as above |
| Holter, memory pass | peak memory MiB | 5 | 3,830 | 3,911 | -2.1% | 2.5% | no significant difference | identical |
FZK with the corrected mark (max(recorded mark, scene.finalize end); the scoreboard traces do not record the first frame with draws):
- Base: all 6 samples streamed and were marked after finalize.
- Branch, 5/6 marked after finalize: 406 [394-444].
- Branch, 1/6 (r1) marked before its drain: recorded 361. Its trace has no finalize, so its corrected value is unknown (at least 361).
- So the corrected branch median lies in [404, 417.5]: a gain of 22.8-25.3%, above the 2x floor even in the worst case.
FZK cold stages (median ms, base → branch):
| stage | base | branch |
|---|---|---|
geometry.streamComplete | 459 | 196 |
parser.complete | 410 | 353 |
| first visible geometry | 319 | 202 |
file.read start | 107 | 152 |
engine.init end | 131 | 175 |
parser.start | 149 | 209 |
Why the parser starts later (149 → 209 ms). The 60 ms come in two parts:
- About 45 ms are already there before the parser stage.
file.readstarts 45 ms later on the branch (107 → 152 ms after the pick), and everything after it shifts with it. Nothing in this PR's code between the pick and the read was measured to take that long. The pick hands theFileto the spare worker with onepostMessagebefore the interface reset. This part is unexplained: it was not profiled. Candidates are that hand-off and main-thread work, such as GC of the idle warm-ups. - About 16 ms are ordering. The claimed run's events arrive as one burst. The loader appends them (first append at 187 ms) before it reaches the parser start. On base, the parser starts while the pool is still booting.
The parse is still 57 ms earlier: the spare parser skips the worker boot, and its parse takes 146 ms instead of 261 ms.
Larger files. The spare parser does not measurably move Holter's or BWK's parse:
| stage, median ms | Holter base | Holter branch | BWK base | BWK branch |
|---|---|---|---|---|
parser.start | 329 | 311 | 474 | 471 |
parser.complete | 3,067 | 3,086 | 3,158 | 3,128 |
Boot, no file opened (n=5, idle read 60 s after navigation):
| base | branch | |
|---|---|---|
| idle PSS, MiB | 621 | 683 |
| idle JS heap, MiB | 51 | 63 |
| idle wasm, MiB | 0 | 19 |
| JS realms | 1 | 3 |
- Boot interactive is 486 → 505 ms (+3.8%), inside the cell's own 2x floor of 7.0%. There is no A/A floor for boot.
- This memory is the idle cost above.
Watchdog overlaps (4-5 s health passes during the slots):
- FZK base warm1 r5 and boot base r3 (marks and idle read outside the pass);
- Holter memory-pass branch r4.
No FZK cold sample overlaps. Package temperature is not recorded by this harness.
Confirmation on the final code (timed, exclusive slot on Pop, 2026-11-13 12:07-12:33Z, harness with #10012 + #10043)
Base c0c2b280d1 = main + #9855. Branch bf5a8079c6 = that + this PR (product code of 0b9c02685d). Both sides carry the same measurement-only commit with #10012's viewer settled hook, so every mark uses the viewer's own settled check. n=6.
| cell | base | branch | current mark | presented-frame mark | verdict |
|---|---|---|---|---|---|
| FZK cold | 497 | 405 | +18.5% | +17.3% | no significant difference at 2x floor 21.7%; every branch sample (392-430) is below the base median (497.5) |
| FZK warm1 | 512 | 402 | +21.5% | +22.2% | gain |
| FZK warm | 504 | 393 | +22.0% | +21.4% | gain |
| Holter cold | 3,388 | 3,337 | +1.5% | +1.9% | no significant difference; post-finalize stalls base 1/6, branch 0/6 |
| BWK cold | 3,203 | 3,189 | +0.5% | +0.5% | no significant difference; stalls 0/6 and 0/6 |
| boot interactive | 521 | 524 | -0.7% | no significant difference (one branch sample at 1,435 ms) | |
| idle PSS at 60 s, MiB | 616 | 678 | +62 | the stated idle cost |
- #10012's checks: 0 flagged samples of 60. The new gate held one fast-path sample by 103 ms, marked at 398 ms instead of 342.
- Per-element output: identical in every cell.
- One FZK branch sample overlapped a host watchdog pass.
Tests
New tests:
pickStart.test.ts: order with nothing to await, a throwing starter, unregister.fastPathRuntime.test.ts:- eligibility;
- never starts while a load runs, including a load that starts during the engine compile;
- claim on matching settings and cancel on a mismatch;
- unclaimed runs dropped and refilled after the load;
- worker error and the first-event deadline; release mid-warm-up, including an interrupted preparation;
- release after hidden or inactive, with re-arm;
- the loader-side fallback and abort.
spare-parser-worker.test.ts(parser): ready only after the warm parse, one spare at most, release mid-warm-up.stepSource.test.tsandfastPathKillSwitch.test.ts: the STEP header check, and?perf.fastPath=0and the registry default.useIfcLoader.fastPath.real-ifc.test.tsx: through the real loader and engine, a claimed run gives the same meshes and data store; fallback, Cancel and supersede.tests/e2e/small-file-fast-path.e2e.spec.ts: equivalence on building-architecture and FZK; a ZIP named.ifc(run not used); a generated 2-10 MiB instanced file (same instancing).
Each core rule has a single-line mutation that must fail a named test (fleet check job).
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Small
.ifcfiles can use a prepared processing path during loading. It runs only for eligible files and matching settings; other files continue through the standard pipeline. - You can disable this behavior with
?perf.fastPath=0.
- Small
- Reliability
- If the prepared run fails before producing geometry, loading falls back to the standard pipeline. Aborted loads cancel pending work.