Repository navigation
perf(ratchet): raise viewer-eager-js-bytes by 8,000 B for the streaming drawing API and its viewer consumer (#10264) - #11234
Conversation
…ng drawing algorithm (#10264) #10892 makes the drawing-2d generator stream: DrawingSession, the projection collector and the open-surface accumulator become the generator's only algorithm. drawing-2d ships as one eager chunk because the store, command palette and PDF-view helpers need its values synchronously at boot, so the algorithm adds ~3.6 KB to the eager bundle. A lazy split of the generator was investigated and rejected (see the PR). Approved by the user. Ceiling 13,465,340 -> 13,470,340 (allowed 13,478,805 -> 13,483,810); measured main 4ed6e97 13,478,233 B, main + #10892 13,481,853 B (local measure-bundle; CI reads ~130 B higher). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@Mergifyio queue |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 6a5e0aba-449f-4209-a73a-be2b71d4eebe) |
❌ Left the queue · checks interrupted36 min in the queue, less than a minute of it CI. So far
Reason The merge conditions cannot be satisfied: the checks were interrupted before producing a result
Failing checks:
To get back in the queue
Merge conditions not met when it left the queue
Requeue requested — the merge queue status continues in this comment ↓. 5 merge conditions met
Times in UTC · dashboard · how the merge queue works |
Claude review - no findings for
|
|
[Low impact] This ceiling-only change appears safe to merge. Reviews (1) · Last reviewed commit: "perf(ratchet): raise viewer-eager-js-byt..." · Reviewed by Greptile |
|
@Mergifyio dequeue |
|
@Mergifyio dequeue |
☑️ The pull request is not queued |
1 similar comment
☑️ The pull request is not queued |
… in total The user approved one ceiling for the streaming drawing API (#10892) and its viewer consumer (#10893): 13,465,340 -> 13,473,340 (allowed 13,486,813). #10893 moved its geometry source and mesh filter to load on first drawing (+8,116 -> +2,495 B); what stays eager is synchronous. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Mergifyio queue |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: fd249f3b-a3ca-4951-98ba-c0b79755bac9) |
🛑 Queue command cancelledQueue requested — the merge queue status continues in this comment ↓. |
🛑 The queue request has been cancelled: new commits were pushedDetails@louistrue pushed to this pull request after |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 813b1268-c12f-41d8-8fd1-03f9821fa4c3) |
|
@Mergifyio queue |
✅ Merged into
|
Claude review - no findings for
|
… (#10892) Part of #10264 (geometry release prerequisite: drawing readback). Stacked on #10884. Product release stays off. ## On main 89b9ba6 (after the eager ceiling raise #11234): head 2ba1ffe - **Merges:** main 7a8fb46 (20 add/add conflicts from #10884's squash, resolved with merge-file against 2f5e82e; git had also duplicated two tap tests that main moved, restored to main's file, which this PR does not touch), then main 4ed6e97 and 89b9ba6, both without conflicts. This PR's diff against main is its own drawing-2d files, identical in content to its original diff. - **Fix:** the README's streamed-geometry samples declare their host inputs (doc-sample check, 520 snippets). - **Exact-head validation on 6e12ed7** (merge-base 7a8fb46), still valid because the later main merges are conflict-free and touch none of this PR's files: fleet full validation green (build, API surface, root typecheck, pre-handoff with the oracle; renderer 2,950 pass / 2 skipped; viewer shards 6,550 / 6,487 / 5,544 / 6,808 pass, 0 failed, 0 cancelled); real GPU (Pop NVIDIA, fixtures copied) 8/8. drawing-2d vitest 735 passed / 1 skipped. - **Eager bundle:** this PR adds ~3.6 KB to the eager `drawing-2d` chunk (the streaming algorithm is the generator's only algorithm). The user approved the ceiling raise in #11234 (viewer-eager-js-bytes 13,465,340 -> 13,473,340, allowed 13,486,813). On 89b9ba6, which also defers STEP export (#11248), local measure-bundle gives 13,291,206 B. - **Review rounds on 384bee2 (final):** - Multi-material open shells (open-surface.ts:90, raised twice): settled with a test. A two-material open tube whose layers' cut chains close only entity-wide (corner split, and mid-wall split with coincident section endpoints) draws exactly as main's pre-session generator (89b9ba6 digests pinned), as one batch and with one layer per batch. Detection is per entity in both. - `DrawingSession.finish()` refuses until its occlusion phase fed what `endGeometry()` asked for, rechecks the signal before returning (an abort from a progress callback returns no drawing), and `addGeometry` rechecks the phase after a GPU cut's await. Witnesses fail before and pass after. drawing-2d 740 passed / 1 skipped. The stream-source oracle was regenerated. - **Follow-ups (past the cap, not reachable in the product viewer, which uses `generateFromSource` and never passes a GPU device):** serialize the shared GPU cutter's `cutMeshes` across concurrent sessions on one generator; per-batch/per-mesh accounting in the `finish()` guard (`addOcclusion([])` satisfies a depth raster; an entity's first mesh marks it fed; a `cancel()` from the `complete`/1 progress report still returns the already-finished drawing); expand degenerate depth-raster bounds; check retention after each settled batch in the session test. - **Exact-head validation on 2ba1ffe (merge-base 89b9ba6):** fleet full validation green: build, API surface, root typecheck and pre-handoff (oracle included) exit 0; renderer 2,970 pass / 2 skipped; viewer shards 6,617 / 6,504 / 5,561 / 6,833 pass, 0 failed, 0 cancelled. drawing-2d vitest 740 passed / 1 skipped. GPU: 8/8 on 6e12ed7; not rerun, as the backing GPU specs don't cover drawing-2d. ## What `Drawing2DGenerator.generateFromSource(source, config, options, profiles?)` draws from a `DrawingMeshSource`, a replayable source of mesh batches, instead of one resident array. - It reads at most two passes: `geometry` (section cut and construction projection) and, only when hidden lines or an open surface need it, `occlusion` (depth raster and the #8664 free-edge test of entities whose cut left open chains). - Between batches it keeps 2D output, one depth raster (resolution²) and welded edge parity for the open-surface candidates. It keeps no mesh, so a source can release each batch when the generator asks for the next. Working input is one batch. Final 2D output is as large as the drawing. - `generate(meshes)` runs the same code over a one-batch source. No second algorithm was added. The shared stages were split to support this: `ProjectionCollector` (moved out of the generator), `HiddenLineClassifier.beginDepthBuffer/addOccluders` (incremental raster; the per-pixel minimum does not depend on order), and `OpenSurfaceAccumulator`/`openSurfaceCandidates` (the same parity as `hasFreeEdge`, fed across batches). - `GeneratorOptions.signal` aborts between batches. A source error rejects the drawing, and nothing partial is returned. - **Push session for bounded consumers (caps, plan cuts, view PDF; #10887 coordination).** `beginDrawing(config, options, profiles)` returns a `DrawingSession`. Call `addGeometry(batch)` for each batch, then `endGeometry()`, then `addOcclusion(batch)` for each batch, then `finish()` (or `cancel()`). `endGeometry()` returns `DrawingOcclusionNeeds`: `depthRaster` means every batch must be fed again, otherwise only the meshes of `openSurfaceEntities` are needed. Nothing from a batch is kept once `addGeometry`/`addOcclusion` settles, so the caller can release each readback lease before taking the next. The generator's algorithm now lives in the session, and `generate`/`generateFromSource` drive it, so joins across chunks, projection bands and occlusion stay one implementation. Each session owns its classifier and polygon builder. Contract comment: #10892 (comment) - `StoreyFloorLevels` computes `storeyFloorsFromMeshes` one batch at a time. The real consumer is the viewer drawing in the stacked PR. ## Current head 0e6d11e (#10884 at 2f5e82e merged in) This head only merges the layer below (#10884's flat overlay fix); no drawing-2d file changes. ## Head f0f9618 (#10884 at 64b24b1 merged in) - The merge is clean, and this layer has no change of its own since 2524735. - `@ifc-lite/drawing-2d` locally on #10893's head, whose package tree is identical: 731 passed, 1 skipped, and `tsc` 0 errors. - The evidence below is from earlier heads. The notes on #10884's API surface and typecheck are carried from them and were not re-checked on this head. - Exact-head validation (root typecheck, API surface, pre-handoff) runs at queue time through the fleet, after #10884 lands and this PR retargets to main. ## Evidence - `drawing-stream.golden.json` holds digests that the pre-streaming generator (base `173774d1a2`, unmodified source copy) recorded over five scenes. The scenes cover plan, front and flipped sections, projection bands and a custom plane, with layered fills, an open sheet, an RTC origin, a second model, an opening and an occluded post. The array API still matches those digests exactly. - Batch sizes 1, 2, 3 and 5 produce the same digest. At most one batch is leased at a time, and no lease is live afterwards. - No mesh or geometry array handed to the generator is reachable from the drawing. - The second pass happens only when it is needed. A source failure in either pass, or an abort, rejects the drawing and releases its lease. - The push session, fed one mesh at a time, reproduces every golden digest. A cut-only session asks only for the open sheet's entity and matches the array API. No added mesh is reachable from the session or the drawing. Phases are enforced, and cancel and abort are refused. - Revert oracle: `tests/evidence/drawing-stream-source-10264` (key `drawing-mesh-source.ts`; the mutation drops the session's free-edge feed in `addOcclusion`). Checked locally: 5 tests fail, and with the patch restored all 39 pass. - Fleet (PC, `73ab42de`): build passed, and the `@ifc-lite/drawing-2d` test package passed. - `scripts/api-surface.json` now has the new drawing-2d exports. - The API-surface check still fails only on `@ifc-lite/renderer` `materializeShardOccurrences`. That export comes from #10884 and is not recorded there yet; this PR does not fix it. - The root typecheck stops on `apps/viewer/src/lib/geometry-backing/readback-raycast-feeder.test.ts(153)` (TS2769), which is also a #10884 file. A re-run on the new head is in progress. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Summary by CodeRabbit * **New Features** * Generate 2D drawings from streamed mesh batches or feed geometry incrementally through a drawing session, with support for cancellation and errors. * Collect storey floor levels incrementally from mesh batches. * Streamed drawing generation handles occlusion and open-surface edges across batches. * **Documentation** * Added API and guide documentation for streamed geometry and incremental floor-level collection.
…1389) ## What GPU instancing in the browser batch path is decided **per batch call**: a geometry instances only when eight copies land in one batch. What instances, and how many templates a model gets, therefore depends on batch size and worker count. This PR adds an **opt-in** plan that decides it once per model from facts the pre-pass already has: - **Mapped sources** whose model-wide `IfcMappedItem` count reaches the gate. Install with `setGlobalInstancePlan(sourceIds, counts)`, fed by the new `mappedInstanceCounts` column. A styled source is matched by its item ids, because its meshes are keyed by item content, not source id. - **Content keys**: elements with structurally identical geometry items. These are planned by the streaming pre-pass when `setGlobalKeyPlanning(true)` is set, and shipped per job as `planIndex` (`addGlobalKeyPlan`). Class-toggled classes never count or plan. Under a plan, **meshing runs exactly as without one** (the per-batch don't-bake placeholders are disarmed). Every flat mesh and every geometry fingerprint is therefore the unplanned batch's, and model compare keeps working for instanced elements; this was the main gap left by the M9 spike. The partition then routes planned, instanceable meshes to the IFNS shard: - It keys them by (plan entry, pre-placement identity ⊕ local topology). - It takes each template back to its local frame once per batch. - It verifies every occurrence against that template with the #3666 recomposition gate (`ifc_lite_geometry::recomposes`, floored at 0.1 mm). A mismatch goes flat. - It writes through the existing IFNS encoder and appends an `IFNL` key trailer. Every keyed record carries its geometry, so shards are self-contained. A worker can be replaced or its engine rebuilt without any cross-shard dependency, and cache replay of any subset works. Decoders that predate the trailer read an ordinary shard (the Rust and TS decoders are both tested). The viewer side (worker pool, keyed join in the renderer, `?perf.globalInstancing=1` flag) is the companion PR. Nothing arms the plan without it. ## Flag off / no plan: unchanged No new code runs in the batch. The pre-pass emits the same events plus the `mappedInstanceCounts` column. Evidence: - **4,911 tests** in `ifc-lite-wasm`, `ifc-lite-geometry` and `ifc-lite-processing` pass, including batch parity (`batch_parity_expected.json` untouched), the mesh-determinism manifests and the structural parity suites, with the in-tree fixture corpus present. - The watertightness census (`watertightness_census_and_triangulator_invariance`, heavy fixtures included) passes against the unchanged goldens. - `pnpm test:wasm-contract`: 262 passed, 0 failed. The one skip is the retained-baseline fingerprint fallback, which needs `IFC_WASM_BASE_*`. ## With a plan: verified against the flat reference `global_instancing_parity_tests.rs` runs the real partitioned batch at three worker×batch splits (1×512, 3×7, 4×1). Each run is compared per element with the flat batch: - every fingerprint is identical; - the same elements are present, with the same triangle counts and colours; - world boxes are within 1 mm; - meshes that stay flat are byte-identical; - the template set and the instance count are identical at every split. It runs on committed FZK-Haus and `mapped_instances_synthetic`. An ignored variant (`IFC_LITE_GLOBAL_PLAN_MODELS=…`) was run on nine real models: | model | elements | instances | templates | |---|---|---|---| | advanced_model | 6,650 | 5,826 | 202 | | Holter Tower | 60,912 | 64,336 | 655 | | skolebygg | 5,555 | 5,153 | 222 | | schependomlaan | 3,589 | 1,250 | 99 | | BIMcollab ARC | 1,401 | 1,231 | 84 | | Snowdon structural | 1,516 | 13,487 | 313 | | BWK | 16,916 | 25,244 | 987 | | duplex | 286 | 70 | 8 | | dental_clinic | 3,258 | 1,050 | 27 | All pass every assertion above. (Counts are from the run before the last review fix dropped the sub-mesh index from mapped keys; that re-run is part of the pre-queue validation.) New contract cases cover: - plan events present only under key planning; - a mapped plan instancing a source in one batch while unplanned repeats stay flat; - a content-key plan instancing direct geometry, with class-toggled classes kept flat; - the old TS decoder reading keyed shards; - unchanged fingerprints; - instance world boxes matching the flat geometry. ## Perf verdict - Flag off: no hot-path change beyond one mutex read per batch and one `u32` column per load. Byte identity is shown above. No timing claim. - Flag on: the GPU and draw effects are measured on the viewer PR. Worker CPU stays at today's viewer cost, because meshing is not skipped (placeholders + fingerprints from templates is a follow-up). - Known next wall: key planning hashes every job before the first dispatch, which adds pre-pass latency under the flag. ## Known limits - The plan's gates count `IfcMappedItem` records and unvoided jobs. Some members never instance (transparent, textured, more than 16 sub-meshes), so a key can end up with fewer than eight real instances. This costs efficiency only. - Meshes of a styled source reached through a nested map stay flat. - Instance transforms carry the post-RTC world translation as f32. Models beyond the RTC threshold keep the per-batch path. Public surface: `setGlobalInstancePlan`, `addGlobalKeyPlan`, `setGlobalKeyPlanning` (regenerated `pkg/ifc-lite.d.ts`, `docs/api/wasm.md`), and `ifc_lite_geometry::recomposes`. ## Blocker: perf ratchet `bundle/engine-wasm-bytes` The engine WASM measured 10,584,744 B on CI, 13,555 B (+0.13%) above the 10,571,189 B ceiling. That is 2,984 B over the allowed ceiling plus tolerance (10,581,760 B). The growth is the plan's code: the three entry points, the keyed partition, the content-key pre-pass and its hash maps. Raising a ceiling is a human-approved PR (as in #11209 and #11234), so this PR does not touch `tests/perf-ratchets/bundle.json`. It needs either an approved ceiling raise or a size cut before it can queue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Summary by CodeRabbit * **New Features** * Added opt-in global instance planning for GPU processing, using model-wide mapped-item counts and optional key planning. * Added pre-pass events with planning details, including job plan indices and mapped-instance counts. * Added keyed mesh shards while preserving compatibility with existing readers. * **Bug Fixes** * Ensured processing without a plan produces byte-identical output to previous versions. * **Documentation** * Documented the planning controls, pre-pass events, and shard format.
Raises
bundle/viewer-eager-js-bytesby 8,000 B so the streaming drawing API (#10892) and its viewer consumer (#10893), both part of #10264, can land. Approved by the user: first +5,000 B for #10892, then amended to +8,000 B so one ceiling covers both drawing PRs. Onlytests/perf-ratchets/bundle.jsonchanges.toleranceis unchanged.Provenance is set to the main commit measured, 4ed6e97.
What grows and why it has to be eager
#10892 turns the drawing-2d generator into a streaming one.
DrawingSession, the projection collector and the open-surface accumulator become the generator's only algorithm, andgenerate(meshes)now drives the session too. The array API's output is pinned to digests recorded by the pre-streaming generator.The viewer ships drawing-2d as one eager chunk (
vite-chunks.ts, the recursivedrawing-2dgroup). Eager code needs drawing-2d values synchronously at boot:The algorithm therefore rides that chunk.
Measured with
scripts/perf-ratchet/measure-bundle.mjson local builds (CI has read about 130 B higher):drawing-2dchunk (167,905 → 171,520 B).What was tried instead
A lazy split of the generator was investigated and rejected:
package.jsonhas no"sideEffects"field, so eager imports through the barrel keep every module. Splitting would need either a side-effects declaration on a published package, which affects every consumer and needs an audit, or deep-subpath imports for the boot values.The drawing-readback viewer layer (#10893)
#10893 first added 8,116 B eager: the drawing geometry source (resident and released meshes, instanced readback) and the mesh filter, all imported by
useDrawingGeneration, which mounts at boot. It now loads them on first drawing through a dynamic import in the drawing compute. That brings it to +2,495 B.What stays eager is needed synchronously:
drawingHasGeometrydecides on every render whether an instanced-only model can draw, and theuseInstancedDrawingRevisionhook makes shard arrival a drawing input. Moving only the readiness half lazy would split the sharedpresence()helper into its own eager chunk, and the estimated net was about 500 B.Making the whole drawing compute lazy, which means restructuring the ~1,000-line hook, was considered and not taken: larger and riskier than this layer warrants.
🤖 Generated with Claude Code
Summary by CodeRabbit