perf(viewer): keep a cache hit's inflate, overlay parse, search index and compaction out of the reopen's interactive window

Merged
LO
18d ago
+2259-107

Peak memory on reopen (Holter, 170 MB): 2,196 → 1,729 MiB on the first reopen (−21.3%) and 2,214 → 1,735 MiB on the snapshot reopen (−21.6%). Timed memory pass, slot D' on Pop: exclusive, 5 interleaved rounds, 0 of 32 samples under load. Base is main@3ad8eae12e and branch f976a623a6, both built with the scoreboard identity commit. Cold peak memory shows no significant difference. Both verdicts hold without the 6 samples that overlapped fleet-watchdog passes (2,215 → 1,727 and 2,230 → 1,736 MiB).

Landing order: #9790 (Tier-0/tier-1 match parity) must land before this PR. The search hand-over below relies on the two tiers returning the same rows.

Summary

Reopen lane, step 2, following W2 (#9728). This removes main-thread work from the window between "model on screen" and "interactive" on a cache hit. Output is unchanged.

changewhat it doeswhere the time was (Holter first reopen, exclusive-slot profile c1b26815)
inflate on workersA cache hit's compressed geometry chunks inflate on a ChunkInflatePool: the cache's compression worker with a new inflate op. The pool is the lazy subpath @ifc-lite/cache/chunk-inflate-pool. Its workers start at the entry's header only if a chunk is compressed. A failing, stalled (5 s) or wrong-length worker falls back to inflating here. A chunk that also fails here is corrupt: it and the remaining chunks reject with CorruptChunkError, and the cache's corrupt-entry path runs at once.Chunk decode was 352 ms of main thread, about 150 ms of it in DecompressionStream plumbing.
one after-load schedulelib/perf/afterLoadIdle.ts runs every post-load job: snapshot write, then overlay parse, then compaction, then tier-1. Each runs after its model settled, in an idle period (1 s timeout; at once in a hidden tab), and is bound to the model's record and store.See the three rows below.
overlay parse after loadDeferred only for a store whose own model is loading. A store keeps its last same-frame parse on screen while a re-parse is pending.The source clone into the overlay worker plus the line-overlay build: about 120 ms in the store-ready → interactive window.
tier-1 search index after loadIt is the model's search-index job. Tier-0 answers meanwhile, as it already did during a build.search.tier1: 1,816–2,456 ms, overlapping the settle at 2,417 ms (473 ms with #9629).
source compaction after loadThe loader schedules it as the model's source-compaction job, so it is not cloned in the settling task. It is never run for a removed model.69 ms in the task that settles the load, which delayed the interactive frame.

Settled (modelLoadSettled, the one definition) means all of the following:

  • The model's record is not in a load phase (pending, streaming-geometry or hydrating-metadata, the phases streaming-refresh.ts treats as loading).
  • The primary geometry stream is not running for it.
  • hasPendingInstancedShards(modelId) is false. That is #9628's rule on main; a shard-queue change re-checks.

A store with no record (the legacy path) is settled when no load and no stream run. Another model's load never holds a settled model's work back.

Lifetime: a job is dropped, with everything it references, when its model's record leaves models or its data store is replaced. That covers removal, a reload under the same id, and a session reset. Its AbortSignal aborts at the same time, also for a job whose work has already started. This follows the repo's "the record is the ownership" rule, as createRunSlot does. createRunSlot and createLifetime themselves own one slot or resource; this queue holds many jobs, each owned by a model record.

Order and holding: one job starts per idle period, earliest kind first among the jobs the queue has. The snapshot write enters once its cache entry is stored, so on a cold load whose entry is still being written, ready jobs run before it. The snapshot write and the overlay parse hold the next job until they finish, for at most 15 s. Compaction (worker) and tier-1 (it yields per chunk) do not hold it. Queued jobs of a removed model are swept even while another job runs.

Every change has a test that fails without it.

Dropped: I also had a commit that decoded metadata while the snapshot adoption waits for the renderer. The direction run below showed renderer start-up also needs the main thread, so it moved adoption and first frame about 0.8 s later on Holter with no gain in interactive. It is not in this PR.

Evidence

Timed verdict on f976a623a6 (re-timed after the 2026-11-12 review fixes)

Pop, exclusive benchmark slot 5b25cfc1, 17:42-17:54 CET. 5 interleaved rounds, power profile Balanced, 0 of 96 samples under load. Both sides were built from source with the scoreboard identity commit 294df5e40a merged in; base = main@3ad8eae12e, this PR's base.

fixturefirst reopen, interactivesnapshot reopen, interactivecold
Holter (170 MB)1,835 → 1,654 ms (+9.8%, PASS)1,809 → 1,633 ms (+9.8%, PASS)n.s. (+0.9%)
BWK (327 MB)1,584 → 1,435 ms (+9.4%, PASS)1,579 → 1,429 ms (+9.5%, PASS)n.s.
advanced_model (34 MB)865 → 768 ms (+11.2%, PASS)805 → 702 ms (+12.9%, PASS)n.s.

No regressing cell. UI quiet: Holter +12.5% / +11.8%, BWK +8.1% / +8.8% (PASS); advanced n.s. The earlier verdict on cd4f49f7a3 (Holter +8.0/+8.6%, BWK +10.7/+9.1%, advanced +10.7/+14.8%) is the same within the noise floors; the review fixes did not change the gain.

Output identity: cold IDENTICAL (element hashes) on all three fixtures. Reopens read match (identity pass: reopen = own cold, both sides) on both reopen lanes of all three fixtures, using the 294df5e40a identity signature, which covers geometry bytes. The widened signature (#9863 at 5e80d69c71: placement, uvs, shading, material, attribution, batch bounds) is re-run before this PR is queued.

Grid and annotation overlays on a cache hit: a model's first overlay parse is now an after-load job: it starts at the first idle period after that model's record is complete, also when its store is first seen after the load. Measured (untimed probe in the same exclusive slot, Holter, 3 reps; first request to the overlay-parse worker):

  • this PR: 1,445-2,251 ms after the input, which is 276-500 ms before interactive;
  • main: 1,445-1,556 ms, which is 369-419 ms before interactive.

So the parse still starts before interactive on a hit, as on main. The record turns complete at the finalize publish, before the UI settles, and an idle period can occur in between. Moving it after the settle frame is follow-up work (the metadata-ready → settle stretch, ~400 ms on Holter); it is not claimed here.

Focused tests on f976a623a6

Under the 2026-11-12 rule (no local four-shard suites; the merge queue runs the full suites), these ran through the fleet: PC job 8097934c, clean checkout of f976a623a6.

  • packages/cache vitest: 29 files, 255 passed, 1 skipped.
  • Viewer, 121 files: 803 tests, 797 pass, 0 fail, 0 cancelled, 6 skipped. Selection: every file this PR touches, their direct consumers, and the review-fix tests.
the 121 viewer files
  • src/hooks/ (64): cacheChunkInflater.test.ts, drawingMarkupPersistencePrecedence.test.tsx, sceneSnapshotLoad.coldCapture.test.ts, sceneSnapshotWrite.test.ts, symbolic-grid-section-clip.test.ts, symbolic-meshed-fills.test.ts, symbolic-parse-outcomes.test.ts, symbolic-rich-channels.grid-bubble-dedup.test.ts, symbolic-rich-channels.theme.test.ts, symbolic-spatial-key.differential.review.test.ts, symbolic-spatial-key.test.ts, symbolic-visibility.test.ts, useDrawingMarkupRestoreOnLoad.test.ts, useIfcCache.fullhash.test.tsx, useIfcCache.inflateOffMain.test.tsx, useIfcCache.staleness.test.tsx, useIfcCache.v3TypeCase.test.tsx, useIfcLoader.blankFrame.test.tsx, useIfcLoader.cacheHitTelemetry.test.tsx, useIfcLoader.cacheStaleness.test.tsx, useIfcLoader.completion.test.tsx, useIfcLoader.coordinateCache.real-ifc.test.tsx, useIfcLoader.federatedAlignStaleGuard.test.tsx, useIfcLoader.federatedCancel.test.tsx, useIfcLoader.federatedIdOffset.test.tsx, useIfcLoader.federatedInstancedShardsTdz.test.tsx, useIfcLoader.gaussian.test.tsx, useIfcLoader.gaussianAdmission.test.tsx, useIfcLoader.gaussianLaunch.test.tsx, useIfcLoader.geometryFailureState.test.tsx, useIfcLoader.glbTextures.test.tsx, useIfcLoader.ifcxStaleGuard.test.tsx, useIfcLoader.instanceOnly.test.tsx, useIfcLoader.landXml.test.tsx, useIfcLoader.loadErrorRetry.test.tsx, useIfcLoader.meshMetadataCache.real-ifc.test.tsx, useIfcLoader.modelProperties.test.tsx, useIfcLoader.noopNotifications.test.tsx, useIfcLoader.onLoadError.test.tsx, useIfcLoader.placementIdentity.test.tsx, useIfcLoader.primaryGlbFederationOffset.test.tsx, useIfcLoader.sabStreaming.test.tsx, useIfcLoader.scanIdentity.test.tsx, useIfcLoader.serverStaleness.test.tsx, useIfcLoader.sharedLoadUi.test.tsx, useIfcLoader.sourceHashOnce.test.tsx, useIfcLoader.staleDeployment.test.tsx, useIfcLoader.streamingStoreTraffic.test.tsx, useIfcLoader.supersededShards.test.tsx, useSearchIndex.lifecycle.test.tsx, useSolarEnvironment.scenario.test.tsx, useSymbolicAnnotations.afterLoad.test.tsx, useSymbolicAnnotations.cacheKeyFrame.test.ts, useSymbolicAnnotations.cacheKeySpatial.test.ts, useSymbolicAnnotations.frameRace.test.ts, useSymbolicAnnotations.gridBubbleExtent.test.tsx, useSymbolicAnnotations.gridChannelSplit.test.ts, useSymbolicAnnotations.hostHideTypes.test.tsx, useSymbolicAnnotations.retryStorm.test.ts, useSymbolicAnnotations.roomOwnerCache.test.ts, useSymbolicAnnotations.rtcPublication.test.tsx, useSymbolicAnnotations.test.ts, useSymbolicAnnotations.visibility.test.tsx, useSymbolicAnnotationsForDrawing.classGate.test.tsx
  • src/components/viewer/ (26): SearchInline.empty-state.test.tsx, SearchInline.i18n.test.tsx, SearchInline.indexing-hint.test.tsx, SearchInline.popover.test.tsx, SearchInline.shortcut-context.test.tsx, SearchInline.wiring.test.tsx, SearchModal.filter.editors.accessible.test.tsx, SearchModal.filter.editors.group.test.tsx, SearchModal.filter.editors.modelFact.test.tsx, SearchModal.filter.editors.names.test.tsx, SearchModal.filter.editors.parent.test.tsx, SearchModal.filter.editors.readOptions.test.tsx, SearchModal.filter.editors.shared.test.tsx, SearchModal.filter.groups.test.tsx, SearchModal.filter.i18n.test.tsx, SearchModal.filter.promote.test.tsx, SearchModal.filter.selector.test.tsx, SearchModal.filter.wiring.test.tsx, SearchModal.i18n.test.tsx, SearchModal.library-entry.test.tsx, SearchModal.library-families.test.tsx, SearchModal.library.test.tsx, SearchModal.text.wiring.test.tsx, SearchableSelect.popover.test.tsx, SearchableSelect.test.tsx, grid-overlay-single-owner.test.ts
  • src/lib/overlay-parse/ (15): drawing-markup-read-real-roundtrip.test.ts, drawing-markup-read-rotation-roundtrip.test.ts, drawing-markup-read.test.ts, overlay-parse.test.ts, overlay-parse.worker.test.ts, profile-entries.test.ts, profiles-golden.test.ts, reply.test.ts, rtc-context.test.ts, source-handoff.test.ts, symbolic-drawing-lines.test.ts, symbolic-flat.test.ts, symbolic-golden.test.ts, symbolic-parse.elevationFrame.test.ts, symbolic-shapes.test.ts
  • src/lib/search/ (13): filter-evaluate-mutations.test.ts, filter-result-to-search-results.test.ts, filter-schema-material-associations.test.ts, filter-schema.effective.test.ts, filter-schema.test.ts, isolate-filter-result.test.ts, recent-searches.test.ts, result-export.test.ts, saved-filters.test.ts, selection-key-column.test.ts, selector-to-rules.test.ts, tier0-scan.test.ts, tier1-index.test.ts
  • src/lib/perf/ (2): afterLoad.test.ts, afterLoadIdle.test.ts
  • src/lib/drawing2d-markup/ (1): drawing-markup-restore.test.ts

Direction only. Pop was loaded at load average 20–50 during this run, so wall times are not a verdict; the exclusive timed A/B comes later.

  • Untimed browser run, 3 reps per side: main + #9728 (89611a3c45) vs this branch before the rebase (80c94b53b9).
  • Holter first reopen, spans:
    • search.tier1 now starts at 5,496 ms, after interactive. On base it started at 3,564 ms, before settle.
    • Chunk decode (39 chunks): 773 → 466 ms wall.
    • Store-ready: 3,181 → 3,123 ms.

First paint on reopen (first geometry frame, median of 3, loaded machine):

fixturelanebasebranch
Holterfirst reopen1,5222,359
Holtersnapshot reopen2,3132,478
BWKfirst reopen3,1952,131
BWKsnapshot reopen2,6892,297
ISSUE_129first reopen1,6641,648
ISSUE_129snapshot reopen1,6311,879
  • Holter's first-reopen regression in this table was traced to the metadata-overlap commit (adoption 1,317 → 2,114 ms), which is now dropped.

  • Reading the rest: the remaining commits don't run before first paint, by construction:

    • the inflate pool only starts its workers before adoption;
    • the three deferrals all run after the load.

    The remaining differences sit inside noise at this load. The timed A/B must still confirm first paint per fixture.

Search hand-over

  • Test: useSearchIndex.lifecycle.test.tsx. A search issued at interactive, before tier-1 is built, answers from Tier-0. After tier-1 is ready, the same queries return the same results in the same order. A separate test fails without the deferral.
  • What the user sees: results immediately. The footer shows "· indexing 1…" until tier-1 is ready. With no Tier-0 match the popover reads "Indexing 1 model… results appear as rows become searchable", not "no results".
  • Hint coverage (fixed in 059e773f58): the hint now covers a model with no index record yet and one whose record was reset to pending, not only building. With the build deferred until the load settles, those states can last a moment. SearchInline.indexing-hint.test.tsx covers it and fails without the change.
  • Result stability across the hand-over: #9790 makes Tier-0 apply tier-1's match rule through one shared function, so results are identical before and after tier-1 is ready. That covers mid-word substrings, multi-word queries and one-letter words, with a parity property test.

Bundle

  • No CI ratchet comment was posted on this PR ("Perf ratchet ceilings" was skipped).
  • I checked the built dist of 059e773f58 instead. ChunkInflatePool landed in the cache package's chunk (src-*.js, 50.7 KB), and index.html modulepreloads it, so it was eager.
  • The pool is now the subpath @ifc-lite/cache/chunk-inflate-pool, imported dynamically by hooks/cacheChunkInflater.ts. A metadata-only entry, or one with no compressed chunks, never loads it.
  • lib/perf/afterLoadIdle.ts (about 1.5 KB) is the shared addition imported by always-loaded hooks.

Export

No export reads the overlay parse, on main or here. useDrawingExport is not given ifcAnnotationData, which only feeds the on-screen 2D canvas (DrawingCanvasView.tsx:86), and the 3D exports do not use it either. Markup restore calls ensureParseFor itself and waits on subscribeToParseCache. So export has nothing to await.

Snapshot write duration (Holter)

The snapshot write now runs first among post-load jobs. Its cache.writeSceneSnapshot span (capture → stored) and encodeMs on Holter, before and after, come from the timed slot on the rebuilt arms. I'll add them here when the slot has run.

Tests (local, merged with main 12fd328582)

  • Viewer, affected groups at 68cee6a59a: 919 tests, 902 pass, 0 fail (the rest skipped). The groups:
    • after-load schedule, overlay/symbolic and overlay-parse;
    • cache hit, decode and lazy inflater;
    • snapshot load/write;
    • search index and search UI;
    • source compaction;
    • instanced-shard queue and drain;
    • geometry streaming, loader, hierarchy.
  • Cache package: 254 pass.
  • Checks: viewer and viewer-embed tsc clean; module-size and frame-wait guards clean; verify-esm-entrypoints passes with the new subpath.
  • The full four-shard suite runs by fleet receipt.

Failing-first: each new hook-level test fails on 059e773f58.

  • A's overlay is held back by B's load.
  • A tier-1 build starts for a model removed by a reset.
  • A removed model's snapshot is stored.
  • A settled model's snapshot waits for another model's load (timeout).

The pool tests for a corrupt chunk and a stalled worker fail on the old pool: one falls back to inflating here, the other hangs.

Focused tests on the shipped code (f8e16dad54; e46a678a25 changes only a changeset)

Fleet job 4a488195 on pop-os, node v24.22.0:

  • cache vitest: 29 files, 256 pass / 1 skip;
  • viewer: 121 files (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), 799 pass / 0 fail / 6 skip.

CI green (19 pass, 0 fail, 0 pending). Unresolved review threads from the API after the last push: 0.

Timed head vs shipped head (f976a623a6 → e46a678a25)

The re-time and the identity proof ran on f976a623a6. The shipped head adds four commits (the last, e46a678a25, changes only .changeset/cache-hit-inflate-off-main.md: the worker inflate covers the opened model's cache hit; a federated add's hit is unchanged):

commitfilechange
4997b94472apps/viewer/src/hooks/symbolic-parse-cache.tsA room-backed (collab room) store's overlay parse records the store's last parse, and getDisplayParseFor shows it while a re-keyed re-parse is pending. The last-parse write moves into a recordLastParse helper, with the same condition.
4997b94472apps/viewer/src/hooks/useSymbolicAnnotations.tsComment shortened from 6 lines to 3 (the 456-line module budget). No code change.
47d0f64e2capps/viewer/src/hooks/symbolic-parse-cache.tsstoreHasParse is also true when the store has a last parse (a rebound room source).
47d0f64e2capps/viewer/src/lib/perf/afterLoadIdle.tsCancelling a STARTED after-load job removes it from the queue's started set (and unsubscribes when nothing is left). Adds a test-only getter.
47d0f64e2cpackages/cache/src/workers/chunk-inflate-pool.tsThe calling-thread fallback inflate (only after the workers failed or could not start) re-checks corrupt after its await and rejects, as confirmHere does.
f8e16dad54packages/cache/src/workers/geometry-compression-client.tscompress() checks the session's failure before the owned-buffer check again, as on main (a failed session reported the wrong reason).
alltestsuseSymbolicAnnotations.roomOwnerCache.test.ts, afterLoadIdle.test.ts, sceneSnapshotWrite.test.ts (awaits the overlay job instead of a 30 ms sleep), chunk-inflate-pool.test.ts (digest includes normals; overlapping fallback). Each new test fails on the previous code.

None of it runs on the measured cold or reopen path before interactive.

  • The room branches run only for room-backed stores, which exist only in a collab room session; no scoreboard fixture (Holter, BWK, advanced_model) has one.
  • storeHasParse and the last-parse write run in the overlay parse trigger and when a parse lands. The overlay parse is an after-load job, so it runs after interactive. For an ordinary store, getDisplayParseFor takes the same path as before.
  • The queue change runs only on a cancel of a job that has already started, which happens after interactive (jobs start only after the load settles).
  • The pool change is in the fallback branch, taken only when no worker can inflate. When the workers inflate (the measured path), this branch does not run; when it does run, the one added check is a field read after the await.
  • The compression change runs in the cache WRITE after a cold load, which starts after interactive. It is one field read; the bytes written are unchanged.
  • No scene, geometry or snapshot code is touched.

Identity: proven on f976a623a6 (normal pass match on 24/24 reopens; altered-snapshot control RESTORE MISMATCH on 24/24; cold identical; section below). It carries over to e46a678a25 because no commit since changes code that produces or compares scene output. The fallback inflate returns the same bytes it did; it only rejects when the entry is already known corrupt. I did not run a third pass: it needs a new viewer build on Pop, and its harness run would queue behind the benchmark slots.

Output identity (scoreboard harness 597b33d034, Pop, 2026-11-12 23:33-00:01 CET)

Arms built with the identity commit: base main 5c7f195588, #9782 f976a623a6, #9782 + #9785 70aadf9b55. Fixtures Holter, BWK, advanced_model. Lanes: cold, then two reopens (warm1 = first reopen, warm). Both sides in every run.

  • Normal pass (base vs #9782; base vs #9782 + #9785): match on all 24 reopens ("pieces = cold, 1 adopted snapshot(s) = written").

  • Cold identical across sides and across all four runs:

    fixturepieceselementspiece siginstanced entitiessnapshot batches
    Holter109,64260,28578d24eee4666dd8a51,095277
    BWK42,34016,395bf5640358a9168c35,872228
    advanced_model11,2236,4017c4c1cb03b454a842,701100

    The written snapshot's own sig differs from run to run on the same base build (four values for main per fixture), so it is not an identity field. Reopens are judged against their own cold.

  • Altered-snapshot control (LOAD_SCOREBOARD_CORRUPT_SNAPSHOT=1, same arms): RESTORE MISMATCH vs cold on all 24 reopens, both sides. The check detects a one-byte change.

  • Untimed (identity only; not timing evidence). Raw: reopen-w2/id597-{normal,control}-{9782,9785}.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Compressed geometry in cached models can now be inflated in background workers, with a fallback to local processing if workers are unavailable or fail.
    • Added a public cache API for worker-based chunk inflation.
    • Search indexing, overlay parsing, scene snapshots, and source compaction now run after the relevant model finishes loading, during idle time.
    • Search remains available while its full index is being built, and existing overlay results stay visible while updates are pending.
  • Bug Fixes
    • Improved search status hints while indexing and preserved display of the most recent compatible overlay parse.