perf(geometry): a flat batch's vertex streams travel as one buffer each; the pool hands meshes views

Merged
LO
17d ago
+255-4

Untimed evidence: done. Timed verdict: PASS on Holter (+5.9% interactive vs a 5.7% 2× floor), no regression.

The verdict is thin on wall time and solid on CPU.

  • Wall time: Holter clears its bar by 0.2 points; BWK (+3.3%) and skolebygg (+0.9%) are not significant.
  • CPU: Holter's CPU total gains +4.1% against a 2.0% own floor.
  • The traced main-thread reduction (−240 ms Holter, −215 ms BWK) is consistent with both.
  • No instruction-count verdict: the stored samples do not carry instruction counts (harness dcbb5ee797 predates that column), so no slot was spent on it.

What

Geometry workers send a flat batch's positions, normals and indices as one buffer each instead of three buffers per mesh. The pool gives every mesh subarray views of them.

  • Every other MeshData field travels on the mesh object exactly as before.
  • Key order is kept: the worker clears the three fields in place, so the main thread refills the same object shape.
  • The canonical appearanceSource fence (both index references are the mesh's own indices) is rebuilt on the index view.
  • A mesh whose arrays are referenced elsewhere travels whole, in its place in the batch, and its buffers stay on the transfer list. That means entityIds, a corner map, or an appearanceSource that is not the identity fence.
  • New module packages/geometry/src/flat-batch-pack.ts. geometry.worker.ts and geometry-parallel.ts change by one call each, with zero net lines (both are at their module-size budget).

Why

Untimed CPU traces of main@65083544b0, sourcemapped, 3 cold loads each:

  • The main thread is 100% busy from about 1.75 s until interactive on Holter. So main-thread work removed anywhere in that range moves interactive.
  • The largest renderer/geometry item on it is the geometry pool's onmessage (geometry-parallel.ts:274).
  • Its self time is the structured-clone deserialization of the batch messages: about 431 MeshData per batch, each with 3 typed arrays on 3 transferred ArrayBuffers.
Holter (r0/r1/r2)BWK (r0/r1/r2)
pool onmessage, inclusive ms367 / 354 / 375302 / 283 / 267
geometry-parallel.ts self ms294 / 281 / 283198 / 193 / 180

Microbenchmark (headless Chromium, Holter-shaped synthetic batches: 132 × 431 meshes, 5 interleaved runs; main-thread ms per load, median):

variantmainworker extra
today's objects1274
metadata packed into columns only9719
vertex streams packed (this PR)76 (−40%)35–74, split over 8 workers
vertex streams + metadata packed4534

This PR takes the variant that leaves every metadata field untouched. Real deserialization costs about twice the synthetic, so the expected gain is about −115 to −160 ms of main-thread time on Holter cold and −75 to −110 ms on BWK. There are also about 170k fewer ArrayBuffer objects per Holter load for the GC.

Risks checked

  • Views pin a batch's buffer until every mesh of the batch drops its arrays. Geometry release and ephemeral streaming release whole models, so a batch is freed then; removing a single element keeps its batch alive.
  • Audit: no main-thread code transfers an IFC mesh's .buffer.
    • cesium-glb copies its own arrays.
    • The cache compression client already copies non-exact views.
    • collab/mesh-codec and authored-grid-meshes respect byteOffset.

Evidence

  • Unit tests (flat-batch-pack.test.ts) on a structured-clone round trip with the transfer list, as postMessage does:
    • delivered meshes equal the originals, with the same key order;
    • one buffer per stream;
    • the fence is rebuilt on the index view;
    • meshes that can't be packed stay whole and keep their buffers;
    • texture and side-channel buffers stay on the transfer list;
    • empty normals, empty batches, and batches with nothing to pack.
  • Geometry tests 91 files / 693 passed; geometry and viewer tsc clean (fleet, 296fd9cc8b).
  • Browser per-element fingerprint against main@65083544b0, 2 cold loads per side: IDENTICAL on FZK, advanced_model, schependomlaan, ISSUE_129, Holter, skolebygg and BWK.
  • Re-traced (untimed): CDP traces with sourcemaps, 3 cold loads each, same host and load. Base main@65083544b0; this branch sits on 975113cecb, which adds only a viewer export feature.
ms (r0 / r1 / r2)Holter mainHolter this PRBWK mainBWK this PR
geometry-parallel.ts self294 / 281 / 283167 / 167 / 168198 / 193 / 18088 / 95 / 99
pool onmessage inclusive367 / 354 / 375241 / 239 / 242302 / 283 / 267166 / 182 / 190
main-thread GC209 / 221 / 205164 / 171 / 156148 / 155 / 130104 / 102 / 105
flat-batch-pack.ts (unpack)—~7—~5

Median self-time change by source, Holter / BWK (ms):

  • geometry-parallel.ts: −116 / −98
  • native (program): −87 / −79
  • GC: −45 / −44
  • unpack: +7 / +5

That is roughly −240 / −215 ms of main-thread work. Traced interactive, a loaded and traced host (ratios only): Holter 4,038 / 4,352 / 4,165 → 3,493 / 3,428 / 3,573; BWK 4,127 / 3,837 / 3,820 → 3,582 / 3,480 / 3,490.

  • Timed verdict (SLOT-RULES capped timing): Pop, one exclusive admission, 14 Nov 2026 05:2x–05:45 CET, harness #10138 dcbb5ee797. Interleaved n=10 per side, browser-cold, CPU trace on. 6 units, every sample inside its cap window, none flagged. Base main@65083544b0; branch 296fd9cc8b (this head adds only a test type fix and the oracle manifest). An A/A of main against itself ran in the same admission.
fixturemetricmainthis PRgainown floorsame-admission A/A floorverdict
Holterinteractive ms3,4013,199+5.9%2.9%2.9%PASS gain
HolterCPU total ms19,85919,054+4.1%2.0%PASS gain
BWKinteractive ms3,3223,213+3.3%4.1%3.6%n.s.
skolebygginteractive ms2,3972,376+0.9%3.4%4.1%n.s.

Per-element output IDENTICAL (20/20 per fixture). Holter main-thread CPU 2,431 → 2,342 ms and stream.queueDrain 289 → 195 ms; worker CPU fell 11,052 → 10,475 ms (fewer transferables to post).

🤖 Generated with Claude Code