perf(viewer): compute whole-model UI values after the load settles

Merged
LO
18d ago
+1498-49

Whole-model derived UI values now wait for the load to settle: the status bar's element count, the model metadata panel's statistics, the viewport hidden/ghosted summary, the IfcGrid / annotation overlay parse, and the drawing-markup restore. Until then each shows its placeholder. After settle they compute once.

Why

These values walk every entity and mesh. Until now they recomputed at the stream-complete flip (the end of useStreamingThrottled's hold) and again on every store publication. All of that fell inside the upload drain and finalize, which end the load. Traced on main+#9684+#9747 (quiet host, sourcemapped, untimed), inclusive main-thread ms between stream complete and interactive:

consumerHolterBWK
ModelMetadataPanel (computeModelStats, mostly its object walk)93–9536
StatusBar object count42–4414
useViewportStatusSummary physical-id set27–2811
useSymbolicAnnotations spatial key58–7815
drawing-markup restore spatial key26–2710
hierarchyGeometry, modelSlice11–145
total~263–280~91

The cold-finalize lane's drain trace (with its M2 step) shows the same family: a 168 ms synchronous commit at stream complete.

Change

  • loadWindow.ts: one load-window signal, held per model.

    • When it is open: while the store is loading or geometry streams. After that it stays open until the geometry tail ends: queued uploads, streaming fragments, renderer finalize and pending instanced shards (geometryTail.ts, identical to #9830's).
    • What it holds: only the models that are loading. A model whose load was complete when the window opened keeps its values while another model loads. It is held again only if it is seen loading again (a reload). In single-store mode legacy is held until the window closes.
    • When a loading model is released: when ITS OWN load has ended. The loader marks that point per model where it settles the load's UI (settleOwnedLoadUi(release, progress, modelId) → markModelLoadEnded, modelLoadEnd.ts). This covers cold loads, cache hits, federated adds and each file of a multi-file open.
      • After the mark: an idle tail (or 3 s from the mark), then a painted frame, with the tail re-checked behind it.
      • For a single load this is the window's own close. The record turning complete is not that point: on a cache hit it comes ~400 ms before the UI settles.
      • Another model's load does not extend the hold. So in a multi-file open (loadFilesSequentially), A's values appear when A's load ends, while B, started at once, is still held.
      • A mark from before the window opened, or from an earlier load of a model seen loading again, is dropped.
    • No finalize-end event: the renderer publishes none, and none exists on main. So once the store flags clear, the window re-checks those constant-time scene flags once per animation frame, with a 100 ms timer backstop for hidden tabs. A real event would need scene.ts, which the cold-finalize lane owns (proposed to them).
    • The close: it lands in a task after the settled frame has painted. It re-checks the tail first, so a fragment arriving between the check and the close keeps the window open (close/reopen race).
    • Limits:
      • 3 s of tail (a finalize that never ends cannot hide the values; this also holds across a restarted tail);
      • 30 s of a store that stays loading (MAX_STORE_BUSY_MS, a stuck flag). Past that the window closes and the consumers compute under main's streaming throttle (#6411).
    • API: useLoadWindowHold().isHeld(modelId) for React. viewerLoadWindow() gives isOpen(), isHeld(modelId), hold() and subscribe() for non-React consumers (the reopen lane's after-load queue, #9915).
  • Consumers gate their inputs for a held model only, so nothing is computed for it while it loads:

    • Status bar: settled models are counted. While only held models exist it shows a dash in a reserved, tabular-figure box (min-w-24), never a provisional 0, so the settled number does not move the bar.
    • Metadata panel: a dash for "Building Storeys" and "Elements with Geometry" of a held model.
    • Symbolic overlays: useSymbolicActiveStores leaves out held models, so they get no parse and no spatial key; settled models keep their overlays.
    • Markup restore: waits while the active model is held.
    • Viewport summary: the hidden/ghosted pill waits while the counted model is held.
  • Id mappings and memos are main's. Each consumer keeps its own mapping:

    • status bar: the scoped resolver, else the raw id;
    • panel: legacy identity, else the federation registry restricted to the model.

    An earlier revision shared one walk between them under one mapping. That memo did not key on the inputs the mapping reads (the model's range, its overlay ids, the registry's progressive publication), and the two mappings differ on unresolved and overlay ids. It is withdrawn, so a settled model walks once per consumer, as on main.

Why the overlays are deferred rather than given a cheap key

The overlay cache key is a content digest of elementToStorey / storeyElevations. It exists because identical bytes can pair with different live hierarchies (#6421), and #9621 deliberately preserved its exact FNV value.

A key built from store identity and version would be unsound. Authored-load paths patch those maps in place without a version bump (setTexturedProductMembership, registerAuthoredElement). A key computed before such a patch would serve a stale cached parse, and a size check would not catch a value change on an existing id. So the overlays wait for settle with the rest.

Visible changes

  • The model that is loading: its count, statistics, pill and overlays appear when its load ends instead of at stream complete; a dash until then. The hierarchy panel is not affected (measured below). The grid fixture's first overlay is within noise.
  • Other models (federated add): no change. A settled model keeps its overlays, count, statistics and hidden pill while another model loads.
  • 2D drawing export during a load: useDrawingExport takes no IFC-annotation overlay data (its inputs are the drawing, the 2D markup and the underlays), so the window cannot change what it writes. Restored embedded markup feeds the export; it is held only for the model that is loading.

Tests

  • loadWindow.test.ts (15 cases):
    • closed outside a load; opens, and closes only after the tail and its painted frame;
    • timer backstop; 3 s tail limit, also across a restarted tail; close/reopen race;
    • 30 s store-busy limit, and no reopen until a new load;
    • per-model hold: a settled model is not held; a reloaded model is held again; a cache-hit model added during the window is held; legacy in single-store mode; immutable snapshots;
    • first read before subscribe; a late subscriber.
  • #6411 restored: main's streaming-hold tests for the status bar (3) and the panel (2), with their assertions unchanged. They run after the store-busy limit, the only place the throttle still applies.
  • Federated (model A settled with overlays and a hidden element, B loads): A's status-bar count, hidden pill, panel statistics, overlay store and markup restore stay; B's appear at its settle.
  • Single-model cache hit and cold load (regression tests for the reopen goal): nothing held computes between the record turning complete and the UI settle. Covered for the window, the status bar (a resolver spy shows no walk), the panel, overlays, the hidden pill and markup restore (no parse). They fail on 2bf9fb1fa4.
  • The mark: settleOwnedLoadUi with a model id publishes it after the release and the UI settle; without one (federated IFCX composition) it publishes nothing.
  • Multi-file open (A's load ends while B starts at once, the store never stops loading):
    • in the window unit tests: A is released at its own settle, B is held; the release re-checks the tail and keeps the per-model tail limit; a released model is held again on a reload;
    • for the status bar, panel, overlays and hidden pill: A's values appear while B is held.
  • Final store after a swap inside the window: for the status bar, panel, overlays, viewport summary and markup restore (one parse, of the final store).
  • Control: every new consumer and window test fails on the previous head:
    • 934f7634e0 for the per-model hold;
    • b5a61cc01a for the multi-file release;
    • 2bf9fb1fa4 for the load-ended release.
  • Markup-restore swap test: it parses distinct bytes and asserts the parse is of the final store (CodeRabbit on #9915).
  • Local runs on 462c14fc59 (repeated on the rebased head 58e3fba74d: 870 pass, 2 skipped, the same 1 local failure):
    • 108 test files touching these consumers, the canceller and the loaders: 869 pass, 2 skipped, 1 fail.
    • The failure is gaussian-startup.test.ts "Dependency outside repository: … -> @ifc-lite/sdk/review". It comes from the local setup: dependencies are linked from another checkout. CI runs it on a clean checkout.
    • viewer typecheck clean;
    • these checks pass: UI drift ratchet, module-size, i18n-literal, jsx-a11y, type-scale, test-glob, changesets;
    • check-unused-locals not run locally (it timed out); CI Lint runs it.

Timed evidence: this PR alone (the shipped head)

Slot a9855, job 60a113c5, exclusive admission. Base: main 22a1b40e84. Branch: + this PR at 58e3fba74d. Production builds, smoke-checked. 5 rounds.

Correctness, checked before timing:

  • data-store digests identical on all 7 scoreboard fixtures;
  • settled frame with overlays pixel-identical on the grid/annotation fixture (8cad59d75bd80940 on both sides);
  • reopen identity pass with the #9863 harness (597b33d034; both identity builds carry its tap): match in all 9 cells (Holter, BWK, advanced_model × cold, warm1, warm), and cold IDENTICAL across sides on all three.
cellmain+ #9855gain (all 5 rounds)gain (without watchdog-overlap rounds)2× floorverdict
Holter reopen (warm1), interactive1,757 ms1,506 ms+14.3%+14.9% (n=3)5.6%PASS
Holter reopen (warm), interactive1,751 ms1,486 ms+15.1%+14.5% (n=3)6.8%PASS
Holter cold, interactive3,711 ms3,453 ms+7.0%+8.0% (n=3)6.3%PASS
BWK cold, interactive3,303 ms3,290 ms+0.4%+0.7% (n=4)4.1%no significant difference
FZK cold, interactive (small-file control)512 ms482 ms+5.9%+5.9% (n=5)21.7%no significant difference
  • Holter: every branch sample beats every main sample, in all three lanes.
  • Everywhere: peak memory, UI quiet and first geometry show no significant difference. No cell regresses.
  • Watchdog overlap: a fleet watchdog pass ran later than the alignment expected. It overlapped Holter rounds 0-1 (both sides, 03:08:41-03:11:23 UTC) and BWK round 0 (both sides, 03:17:56-03:18:34). Both views are in the table, and no verdict changes between them.
  • Hierarchy rows are not delayed by this PR (2 rounds):
    • Holter first rows painted 3,247 / 3,027 ms on main, 2,867 / 3,055 ms with this PR;
    • grid/annotation fixture 459 / 447 → 437 / 443 ms.
  • First annotation overlay (grid fixture): 761 / 742 → 764 / 776 ms, noise.
  • Base caveat: 22a1b40e84 predates #9782 landing on main. The reopen gain on today's main is expected but has not been measured as a pair. The B4 board at 05:00 measures main as it is, and the first board after this PR merges gives the pair's number.
  • Earlier pair arm (with #9830, slot p2, base 000532b2cc): Holter cold 3,663 → 3,353, reopens 1,826 → 1,542 and 1,789 → 1,547. The hierarchy delay measured there (~455 ms) comes from #9830's gate, not from this PR. #9830 stays separate pending that decision.
  • Rebased: onto main 22a1b40e84; head 58e3fba74d.

🤖 Generated with Claude Code