perf(viewer): load BCF validation and Lens panels on demand

Merged
LO
20d ago
+377-11

BCF, Data validation and Lens panel bodies now load on first activation through the shared workspace router. The post-#9616 controlled build pair removes 301,732 raw / 61,868 Brotli bytes from eager JS. Loading and error states retain a translated title and working Close on both mobile and desktop. Model gates, first-model loading and eager Lens evaluation remain available.

Keep unqueued. Exact-head acceptance is complete: the FULL four-shard viewer suite passes, alongside typecheck, lint, lazy audit, retained-free, ratchet and pre-handoff. CI is green and all five review threads are resolved. Recommend landing: the reduction remains useful after #9590 relieved the ceiling emergency. Ready for the orchestrator to queue; this agent has not added mergify-trial.

Paired measurement after #9616

Eager JSExact main baselinePR headRemoved
Raw bytes18,024,17017,722,438301,732
Brotli-11 bytes3,047,6512,985,78361,868
HTML / complete static closure files365 / 365361 / 3614

Exact main 6aefb7833bcc707ef086907b03c030f83e1e9d64 includes merged #9616. Baseline 73bd6298c18c1a04d46e97514a207b1e92010190 adds only four attribution-tool files to main (Vite config/plugin, Turbo environment, audit script). Head 700083eff733780a4c70d88276a199588b054aef. Both use frozen installs and VITE_BUNDLE_ANALYSIS=1 pnpm build:e2e --force --concurrency=1, Node heap8GiB, Turbo concurrency1 and 4CPU/24GiB fleet admission on Pop. Published receipts exit0, source clean/unchanged; worker log SHA-256 verified. Force avoids stale inherited WASM/cache output.

The absolute branch value is 354,443.823 raw bytes below the 18,076,881.823 allowance (18,058,823 ceiling plus0.1% tolerance). Main has52,711.823 bytes of headroom. These absolute values are separate from this PR's exact-base delta; no shared-base savings are credited to the PR.

All emitted JS, including lazy files, rises about21.70kB raw in rounded Vite output (696→719 assets). Total JS Brotli was not measured; this is a small total-output tradeoff for less eager parsing, with no module duplication. No timed benchmark or cold-boot speedup claim.

Attribution and safe seam

Largest current eager chunks by exact raw size:

Chunk familyMain rawHead raw
exporters7,908,3997,908,399
main2,482,1662,180,446
store975,731975,731
sandbox925,296925,296
createLucideIcon767,955767,955
command-palette-layout445,947451,933

Chunk names are not package ownership. Largest head package rendered lengths: viewer8,396,768; parser4,501,474; codegen3,177,816; data3,172,150; renderer1,111,556; create886,909; react-dom536,907; export528,841; PostHog433,041. These are pre-minification attribution, not additive raw-byte savings. The exporters group includes shared parser/data dependencies required for first-model loading, so deferring a single export dialog cannot remove it.

137 modules (551,278 rendered bytes;127 viewer modules) leave the eager closure. Only DeferredPanel and its shared module factories become newly eager (1,817 rendered bytes). Compared with the independently reviewed pair, library-focus now moves instead of useAsyncRun: the former initializes a local Zustand store, with no listeners/network/registration; all consumers are on demand, and native artifact opening stores its target before mounting the panel. The reviewed no-startup-registration reasoning remains applicable. Shared package runtimes and Lens runtime evaluation stay eager.

The audit covers HTML entry/modulepreloads plus recursive static imports. --expect-lazy verifies actual emitted ownership for BCFPanel, ValidationPanel, LensPanel and nested BCFDraftsDialog. CI now enables attribution and invokes this assertion in the existing build/ratchet workflow. No manualChunks grouping changes. Full paired module/package/chunk tables, source proofs and ranked remaining candidates are saved in the task's eager-js-breakdown.md artifact. The ledger is consolidated in #9673; this code PR has no README hunk.

Behavior, reviews and composition

  • All hosts, shortcuts and deep links retain the shared router. Pending/error states have title and Close on every layout; chunk errors stay contained to the panel. Router tests mount real panels against a parsed committed IFC fixture, with bounded observable waits and independent title expectations.
  • The four B1 assistant test failures were reproduced before fixing. Tests now wait for real feature controls; the IDS-side negative assertion first proves the actual Validation wrapper mounted. Production Assistant adapters capture eager store state and never drive panel DOM. Five production router caller files are declarative hosts; persisted artifact requests are consumed on mount.
  • Tours now await the same module factories before starting their DOM deadline, with slow-load/cancellation tests. Offline chunk failures surface without automatic navigation or spending reload budget, with reconnect coverage.
  • The existing mobile registry coverage test was reproduced failing at the shared transparent host; it now unwraps DeferredPanel and checks the actual lazy children, retaining its identity/fall-through invariants.
  • #9590's BCFDraftsDialog remains the unique nested drafts boundary. Merged #9616 (2d1d4c7f37) only defers the profiles dialog and updates readiness tests: no BCF, reusable helper, manualChunks or audit overlap. Its profile/mobile host tests pass in this acceptance selection. MapLibre was already dynamically imported; #9623's map-construction work is independent.

Validation by receipt

Exact head700083e, Pop request auto-922ba0a611eb4111bc6d608107e009db, job a4afb15a-443f-49fd-8d84-551206780c32, published exit0:

  • Forced production build, emitted --expect-lazy, bundle ratchet: PASS.
  • Retained-free: PASS,1,165 files before measurement JSON;1,166 in pre-handoff.
  • Root pnpm typecheck: PASS,136 tasks;4,828 test files in71 packages audited. Root pnpm lint: PASS.
  • Dry-run-verified selection of11 review regression files: 71 pass,0 failed/skipped/cancelled. Includes all four B1 assistant files, real-router and mobile registry tests, loading/error shell, offline, tours and merged profile/mobile host tests. This is not full-suite coverage.
  • node scripts/pre-handoff.mjs --base 6aefb7833b: 14 PASS,0 SKIPPED.

Matching baseline request auto-7582713c3dc5498f834ee3ce3d8ba76e, Pop job b6b807de-8325-4fe2-898c-dcb5fd1e7ce1, published exit0, same pipeline/source qualification.

Preserved original full-suite request (UNKNOWN, not acceptance): original request auto-b202e45dd9ab4b4883455c9115519de1, PC job 7ad5e38a-875e-47c5-b93e-9d951ff4c266, was boot-reconciled orphaned. Its receipt says the host rebooted while it ran; outcome UNKNOWN, never replay. No four final shard summaries, so no full-suite pass is claimed. Original receipt, boot-reconciliation record and UNKNOWN outcome remain untouched. The owner explicitly decided one fresh validation; this is not an automatic replay.

Owner-decided fresh full-suite validation (startup failure, not acceptance): request auto-e1e0ca3edb9d490e82e985c9ca0715f3, Pop job 68e9d780-3afe-4266-ae6d-d2438c441281, exact head 700083eff733780a4c70d88276a199588b054aef. Published exit1, source unchanged, original worker log SHA-256 verified. Installed full Chrome153.0.8010.36 launched successfully; all191 fixtures fetched and hash-verified; helper built all58 dependencies successfully. All four complete shard logs are retained.

ShardProcess exitCases executedTest summary
0/410Not produced: runner startup failed
1/410Not produced: runner startup failed
2/410Not produced: runner startup failed
3/410Not produced: runner startup failed

The submitter's log observer set TMPDIR under the long checkout path, causing tsx's Unix IPC socket path to reach159 bytes and fail with listen EINVAL before test execution. This is a wrapper defect, not a viewer regression or the known timer flake. The observer itself successfully preserved all four complete logs. A lightweight qualification on the same Node24.22.0 and installed tsx4.23.15 reproduces EINVAL with a156-byte socket path and succeeds with a49-byte path. The owner explicitly authorized one corrected request using a short owned /tmp/ifc9634-* directory. Before submission, that same wrapper collected and passed one existing tiny viewer test (root Turbo, selector dry-run verified) and preserved the complete log after helper cleanup. No change to either earlier receipt and no full-suite pass claim. The known timer B1 flake was not reached; its conditional ten isolated reruns have not been invoked.

Corrected owner-decided full-suite validation: PASS. Request auto-8e0b7bfa8378416ba6ab1eea8fd98950, Pop job 214bbf53-306a-4cdb-b870-b6913f667cc4, exact head 700083eff733780a4c70d88276a199588b054aef. Published exit0, source clean/unchanged; original worker output SHA-256 verified (8940f063e1a0b05284fd2ccebbaf747db7e857a607a4c27fbafec1e6bb35f49f). Documented four-shard helper, selectors cleared, 4 CPU / 16 GiB, installed full Chrome153.0.8010.36 launched successfully, all191 fixtures hash-verified. All four complete logs retained, including individual skip reasons.

ShardCasesPassedFailedSkippedCancelled
0/45,7475,742050
1/45,7535,750030
2/45,0355,031040
3/46,1786,175030
Total22,71322,6980150

The15 skips are explicit coverage gaps for optional external prerequisites: LLM configuration/live model catalog(4), captured native inverse fixture(2), Rust OCI registry binary(1), external HTTP/PG/S3 integration(1), appearance corpus opt-in(4), captured boulder mesh(1), and Python IfcOpenShell(2). None is caused by a missing manifest fixture or Chrome. No cancellation or todo. The known useReplaceableTimeout B1 timer test passed; ten isolated reruns were unnecessary.

This corrected request is the full-suite acceptance evidence. The reboot-orphaned request remains UNKNOWN and the long-TMPDIR startup-failed request remains a zero-test failure, with both earlier receipts and original evidence unchanged.

GitHub CI is green and all five review threads are resolved. Supporting run 42908495909 tested integration 29c2009a (head700083 + main8ec82628), measuring17,741,257 raw/2,990,649 Brotli. That integration value is not the controlled delta above. Its typecheck/lint/retained-free/ratchet passed; pre-queue CI skips full viewer tests.

Lowering and follow-ups

Ceilings and tolerance are unchanged. Lower through the sanctioned daily main-only workflow after merge; do not stamp a branch or attribution-only build as main provenance. React.lazy still caches rejected imports for the document lifetime, matching existing panels; app-wide retry/preserved drafts and one-frame loading/focus/header polish remain follow-ups. The offline guard does not make an uncached panel available offline.