perf(parser): keep jszip and decimal.js out of the parser worker

Merged
LO
20d ago
+214-127

Every cold load starts a parser worker, which fetches, compiles and evaluates its whole bundle before it can accept a parse. On FZK that start-up, not the 39 ms data-model parse, ends the metadata path.

What changes

  • The worker imported IfcParser from the package index. The index also reaches .ifczip unwrapping (jszip) and the cost evaluator (decimal.js), so both were in the worker bundle and were evaluated on every start, though the worker uses neither. IfcParser moves to packages/parser/src/ifc-parser.ts; the index re-exports it unchanged (API surface unchanged).
  • The bundle ratchet gains viewer-parser-worker-js-bytes: the raw bytes of the one assets/parser.worker-*.js chunk. None or several is an error, so a renamed worker cannot measure as zero. The ceiling is this branch's build.

Measured

Production viewer builds (sourcemapped, source-built wasm), base 6636d36476 vs this change on the same base:

metricmainthis PR
parser worker chunk4,621,251 B4,491,334 B
entry JS1,971,965 B1,971,965 B
eager JS17,550,991 B17,550,991 B

Worker start-up, untimed and indicative (Pop under ifc-gpu-check, host load 7-10, Chrome 153 headless, a fresh browser process and context per start so no HTTP or code cache, n=10, standalone rolldown build of the same entry that reproduces the production chunk within 0.1%). Time from new Worker to the first queued message handled, median [min-max]:

bundlefirst message
main219 ms [207-344]
without jszip/decimal.js (this PR)141 ms [132-229]
no schema tables either (floor)19 ms [18-29]

Almost all of the 78 ms is evaluation, not compile: evaluate drops 99 → 23 ms. jszip and decimal.js cost about 17 ms alone but about 75 ms beside the schema tables' freshly allocated heap (removing only the tables gives 21 ms, only the two libraries 24 ms).

Landing grounds (shared by #9838, #9839, #9840, #9841)

  • No regressing cell in any lane of the shared timed slot (below).
  • The goal cell did not reach significance: FZK cold interactive, +11.8% against a 21.7% bar. This stack is not a load-time gain on the goal and is not claimed as one.
  • What it does deliver, measured:
    • Bundle (production build, base 6636d36476 vs all four):
      • main-thread eager JS: 17,550,991 → 12,613,295 raw bytes;
      • parser worker: 4,621,251 → 1,447,760 raw bytes (brotli 233,720 → 205,394).
      • The eager JS's brotli size is flat (2,963,206 → 2,982,953, +0.7%): this is less JS to parse and compile, not less to download.
    • Idle JS heap: 60 → 49 MiB (boot lane, no file opened).
    • Boot app-shell ready: 590 → 473 ms. That is above its own floor, but the boot cell has no A/A floor.
    • BWK first-reopen peak memory: 1,779 → 1,720 MiB (passes at 2x its floor).
  • Landing order: #9838, then #9839, #9840, #9841. Each is retargeted to main as the one below merges, and labelled only when its own shipped head has: package validation green; the 25-file focused viewer run green; the BulkPropertyEditor isolation runs explained (#9840); 0 unresolved review threads; CI green.

Timed verdict, shared by #9838 + #9839 + #9840 + #9841

One exclusive slot on Pop (cd8b3235, Balanced profile, maximum 5.3 GHz, no sample flagged for load): main 6636d36476 against all four PRs on the same base (b355265c3b). FZK, Holter, BWK and advanced_model; cold, first and second reopen; 5 rounds; boot lane; memory pass.

  • Regressions: none.
  • Significant gain (at least 2x the noise floor): BWK first-reopen peak memory, 1,779 → 1,720 MiB (+3.3%, 2x floor 3.0%).
  • Goal cell, FZK cold interactive: 598 → 528 ms (+11.8%), inside its 21.7% 2x floor, so no significant difference. FZK cold peak memory 902 → 828 MiB (+8.2%; 2x floor 8.6%, just short).
  • Boot lane (no file opened): app-shell ready 590 → 473 ms (+19.7%; own floor 7.4%). Idle JS heap 60 → 49 MiB; idle agent memory 62 → 50 MiB. Inconclusive by rule: the boot cell has no A/A floor.
  • Output identity: cold lanes identical on all four fixtures. Reopens are unverifiable by design (the cache path carries no element hashes).
  • FZK cold, where the (non-significant) difference went: the metadata path settles about 80 ms earlier (store settled 576 → 495 ms median). Geometry finalisation now finishes about 84 ms later (442 → 526 ms), so FZK ends on geometry instead of metadata. The earlier parser result appears to contend with geometry finalisation on the main thread; this run does not establish that.

Verification plan (in progress; results will replace this section)

  • Timed: one exclusive A/B for all four parser-worker start-up PRs as a unit, #9838 + #9839 + #9840 + #9841 on main 6636d36476, against the same base. FZK, advanced_model, Holter, BWK; cold, first and second reopen; boot lane; 5 rounds; memory pass. All four share that verdict (gain on a cell at 2x the floor, no regressing cell, boot included) and land in order: #9838, then #9839, #9840, #9841, each retargeted to main as the one below merges. Each PR's own identity proof and package validation stand alone.
  • Tests that run before labelling (fleet, pinned to Pop): package validation on this head (build packages, typecheck @ifc-lite/data and its dependents except the viewer, data / parser / codegen tests, codegen-sync, API surface, type parity, perf-ratchet tests including the new metric, pre-handoff).
  • Identity: browser data-store digests, main vs this build, on the 7 scoreboard fixtures + IFC4X3 + .ifczip.
  • Not run locally: the full four-shard viewer suite, which the merge queue runs before anything lands. The change touches no viewer code and no schema-table code: it only moves which module the browser worker imports IfcParser from. Viewer unit tests import the parser through its unchanged index, and do not execute the worker bundle.

🤖 Generated with Claude Code