perf(geometry): a flat batch's vertex streams travel as one buffer each; the pool hands meshes views
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
MeshDatafield 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
appearanceSourcefence (both index references are the mesh's ownindices) 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 anappearanceSourcethat is not the identity fence. - New module
packages/geometry/src/flat-batch-pack.ts.geometry.worker.tsandgeometry-parallel.tschange 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
MeshDataper batch, each with 3 typed arrays on 3 transferred ArrayBuffers.
| Holter (r0/r1/r2) | BWK (r0/r1/r2) | |
|---|---|---|
pool onmessage, inclusive ms | 367 / 354 / 375 | 302 / 283 / 267 |
geometry-parallel.ts self ms | 294 / 281 / 283 | 198 / 193 / 180 |
Microbenchmark (headless Chromium, Holter-shaped synthetic batches: 132 × 431 meshes, 5 interleaved runs; main-thread ms per load, median):
| variant | main | worker extra |
|---|---|---|
| today's objects | 127 | 4 |
| metadata packed into columns only | 97 | 19 |
| vertex streams packed (this PR) | 76 (−40%) | 35–74, split over 8 workers |
| vertex streams + metadata packed | 45 | 34 |
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-glbcopies its own arrays.- The cache compression client already copies non-exact views.
collab/mesh-codecandauthored-grid-meshesrespectbyteOffset.
Evidence
- Unit tests (
flat-batch-pack.test.ts) on a structured-clone round trip with the transfer list, aspostMessagedoes:- 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
tscclean (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 main | Holter this PR | BWK main | BWK this PR |
|---|---|---|---|---|
geometry-parallel.ts self | 294 / 281 / 283 | 167 / 167 / 168 | 198 / 193 / 180 | 88 / 95 / 99 |
pool onmessage inclusive | 367 / 354 / 375 | 241 / 239 / 242 | 302 / 283 / 267 | 166 / 182 / 190 |
| main-thread GC | 209 / 221 / 205 | 164 / 171 / 156 | 148 / 155 / 130 | 104 / 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.
| fixture | metric | main | this PR | gain | own floor | same-admission A/A floor | verdict |
|---|---|---|---|---|---|---|---|
| Holter | interactive ms | 3,401 | 3,199 | +5.9% | 2.9% | 2.9% | PASS gain |
| Holter | CPU total ms | 19,859 | 19,054 | +4.1% | 2.0% | PASS gain | |
| BWK | interactive ms | 3,322 | 3,213 | +3.3% | 4.1% | 3.6% | n.s. |
| skolebygg | interactive ms | 2,397 | 2,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