Skip to content

perf(ratchet): raise viewer-eager-js-bytes by 8,000 B for the streaming drawing API and its viewer consumer (#10264) - #11234

Merged
mergify[bot] merged 3 commits into
mainfrom
perf/eager-ceiling-streaming-drawing
Nov 22, 2026
Merged

mergify[bot] merged 3 commits into
mainfrom
perf/eager-ceiling-streaming-drawing

Conversation

@louistrue

@louistrue louistrue commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Raises bundle/viewer-eager-js-bytes by 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. Only tests/perf-ratchets/bundle.json changes. tolerance is unchanged.

Ceiling Allowed (+0.1%)
Before 13,465,340 13,478,805
After 13,473,340 13,486,813

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, and generate(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 recursive drawing-2d group). Eager code needs drawing-2d values synchronously at boot:

  • the store: 16 values, including GraphicOverrideEngine, BUILT_IN_PRESETS, DEFAULT_SECTION_CONFIG and other drawing/section slice defaults
  • the command palette and bottom-strip header
  • the main entry
  • the shared drawing chunk
  • the view-PDF shading and scale helpers

The algorithm therefore rides that chunk.

Measured with scripts/perf-ratchet/measure-bundle.mjs on local builds (CI has read about 130 B higher):

Build Eager JS (bytes)
main 4ed6e97 13,478,233
main 4ed6e97 + #10892 13,481,853
main 4ed6e97 + #10892 + #10893 (6551cbe) 13,484,348

What was tried instead

A lazy split of the generator was investigated and rejected:

  • The generator is constructed only asynchronously: section caps, plan cut, view-PDF, the Drawing panel and exports. But drawing-2d's package.json has 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 generator's own dependencies (section cutter, polygon builder, edge extractor, hidden lines, line merger, hatch, SVG exporter, GPU section cutter) are partly reached eagerly already. For example, view-PDF shading pulls 10 drawing-2d values. The net gain was uncertain.
  • Earlier lazy splits in this stack moved shared modules into new eager chunks and grew every chunk's preload list.

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:

  • The instanced-presence checks (~1.4 KB minified). drawingHasGeometry decides on every render whether an instanced-only model can draw, and the useInstancedDrawingRevision hook makes shard arrival a drawing input. Moving only the readiness half lazy would split the shared presence() helper into its own eager chunk, and the estimated net was about 500 B.
  • The streamed storey floor levels in the hook (~440 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

  • Chores
    • Updated the measured JavaScript bundle-size ceiling for the viewer. No user-facing behavior changed.

…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>
@louistrue louistrue added unqueued Maintainer waiver: this PR may merge without closing a ready issue. mergify-trial Trial: queue this PR through Mergify batches labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The viewer-eager-js-bytes ceiling increased by 8,000 bytes. The relative tolerance stayed unchanged. The provenance commit and measurement timestamp were updated.

Changes: Bundle size ratchet

Layer / File(s) Summary
Update viewer bundle ceiling
tests/perf-ratchets/bundle.json
The viewer-eager-js-bytes ceiling increased from 13,465,340 to 13,473,340 bytes. The relative tolerance stayed unchanged. The provenance commit and measurement timestamp were updated.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Other

Merge Risk: Minimal · up to af958

This updates a test-only bundle size ceiling to cover two viewer drawing changes. It has no runtime impact, and the reported measurements fit within the new limit.

Pre-merge checks: Passed 7

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: it raises the viewer-eager-js-bytes bundle ceiling by 8,000 B to cover the streaming drawing API and its viewer consumer. The raw summary and objectives confirm that only t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Changeset Bump Matches The Api Surface Passed The check applies only when the PR adds or edits a file under .changeset/. The reviewed range changes one file: tests/perf-ratchets/bundle.json (modified). The .changeset/ path filter returned n…
Verification Evidence Is Present Passed The check applies to PR descriptions that claim user-visible behaviour. This PR does not make such a claim. Its only change is in tests/perf-ratchets/bundle.json: the viewer-eager-js-bytes ceiling…
One Defect Class Per Pr Passed The check applies only when a PR fixes the same defect class at several unrelated call sites. This PR does not fix any defect. The base-to-head diff changes one file, tests/perf-ratchets/bundle.json…
Full details: Title check

Explanation

The title names the change: it raises the viewer-eager-js-bytes bundle ceiling by 8,000 B to cover the streaming drawing API and its viewer consumer. The raw summary and objectives confirm that only tests/perf-ratchets/bundle.json changes and that the ceiling moves from 13,465,340 to 13,473,340 bytes. The title is specific and accurate, though it is long at 116 characters.

Full details: Changeset Bump Matches The Api Surface

Explanation

The check applies only when the PR adds or edits a file under .changeset/. The reviewed range changes one file: tests/perf-ratchets/bundle.json (modified). The .changeset/ path filter returned no entries, so no changeset is touched. The check is inapplicable and passes.

Full details: Verification Evidence Is Present

Explanation

The check applies to PR descriptions that claim user-visible behaviour. This PR does not make such a claim. Its only change is in tests/perf-ratchets/bundle.json: the viewer-eager-js-bytes ceiling goes from 13465340 to 13473340, and provenance moves to commit 4ed6e97. I confirmed this with the branch diff, which lists only that file. The change is a mechanical ceiling adjustment, and the diff itself shows what changed. The description still gives re-runnable evidence. It names the measurement script scripts/perf-ratchet/measure-bundle.mjs, which exists in the checkout. It reports local build measurements for main, main plus #10892, and main plus #10892 plus #10893, with byte counts. It also explains the CI offset of about 130 B. A reader can re-run the named script to check the numbers. The description has some weaknesses. The "approved by the user" note is not verifiable, and the measurements come from local builds rather than a CI run. These gaps do not fall under this check's FAIL condition, which concerns unverified user-visible behaviour claims.

Full details: One Defect Class Per Pr

Explanation

The check applies only when a PR fixes the same defect class at several unrelated call sites. This PR does not fix any defect. The base-to-head diff changes one file, tests/perf-ratchets/bundle.json. It raises viewer-eager-js-bytes ceiling from 13465340 to 13473340 and updates provenance to commit 4ed6e97 (measured 2026-11-22T12:20:14.000Z). tolerance is unchanged. No source, test, or helper code changes, so there are no defect call sites to unify. The PR is a single-purpose budget adjustment, not a multi-site fix. Check inapplicable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b191a3d and af95822.

Files selected for processing: 1

  • tests/perf-ratchets/bundle.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@louistrue

Copy link
Copy Markdown
Collaborator Author

@Mergifyio queue

@cursor

cursor Bot commented Nov 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@mergify

mergify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

❌ Left the queue · checks interrupted

36 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

  • Build + WASM + Rust + Node

Failing checks:

To get back in the queue

  • Look at the check run to find out why it stopped: a reclaimed runner or a cancelled workflow run are the usual causes.
  • Then tick the box below to queue the pull request again as it is: an interrupted check reported no result, so it says nothing about this pull request.

Merge conditions not met when it left the queue

  • check-success=Build + WASM + Rust + Node
  • check-success=Rust tests (feature builds)
  • check-success=Viewer tests (shard 0)
  • any of · required by GitHub repository ruleset rule main:
    • check-neutral = @github-actions/Build + WASM + Rust + Node
    • check-skipped = @github-actions/Build + WASM + Rust + Node
    • check-success = @github-actions/Build + WASM + Rust + Node
  • any of · required by GitHub repository ruleset rule main:
    • check-neutral = @github-actions/parity (in-tree fixtures, committed reference)
    • check-skipped = @github-actions/parity (in-tree fixtures, committed reference)
    • check-success = @github-actions/parity (in-tree fixtures, committed reference)

Requeue requested — the merge queue status continues in this comment ↓.

5 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection and GitHub repository ruleset rule main
  • any of · required by GitHub repository ruleset rule main:
    • check-skipped = @github-actions/Issue queue
    • check-neutral = @github-actions/Issue queue
    • check-success = @github-actions/Issue queue
  • any of · required by GitHub repository ruleset rule main:
    • check-skipped = @github-actions/PR review signal
    • check-neutral = @github-actions/PR review signal
    • check-success = @github-actions/PR review signal
  • any of · required by GitHub repository ruleset rule main:
    • check-success = @github-actions/CLA
    • check-neutral = @github-actions/CLA
    • check-skipped = @github-actions/CLA

Times in UTC · dashboard · how the merge queue works

@github-actions

Copy link
Copy Markdown
Contributor

Claude review - no findings for bc15f87ec

Reviewed this diff and found nothing to flag.

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in Greptile

[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

@github-actions github-actions Bot added the llm-reviewed A review was verified as posted for this PR's head. label Nov 22, 2026
@mergify mergify Bot added the queued label Nov 22, 2026
@github-actions github-actions Bot added the base-stale Tested against a base that has since moved in a way a whole-tree snapshot cares about (#3726). label Nov 22, 2026
@mergify mergify Bot added dequeued and removed queued labels Nov 22, 2026
@louistrue

Copy link
Copy Markdown
Collaborator Author

@Mergifyio dequeue

@louistrue louistrue removed the mergify-trial Trial: queue this PR through Mergify batches label Nov 22, 2026
@louistrue

Copy link
Copy Markdown
Collaborator Author

@Mergifyio dequeue

@mergify

mergify Bot commented Nov 22, 2026

Copy link
Copy Markdown

dequeue

☑️ The pull request is not queued

1 similar comment
@mergify

mergify Bot commented Nov 22, 2026

Copy link
Copy Markdown

dequeue

☑️ 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>
@louistrue louistrue changed the title perf(ratchet): raise viewer-eager-js-bytes by 5,000 B for the streaming drawing algorithm (#10264) perf(ratchet): raise viewer-eager-js-bytes by 8,000 B for the streaming drawing API and its viewer consumer (#10264) Nov 22, 2026
@github-actions github-actions Bot removed the llm-reviewed A review was verified as posted for this PR's head. label Nov 22, 2026
@louistrue louistrue added the mergify-trial Trial: queue this PR through Mergify batches label Nov 22, 2026
@louistrue

Copy link
Copy Markdown
Collaborator Author

@Mergifyio queue

@cursor

cursor Bot commented Nov 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@mergify

mergify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🛑 Queue command cancelled

Queue requested — the merge queue status continues in this comment ↓.

@mergify mergify Bot removed the dequeued label Nov 22, 2026
@mergify

mergify Bot commented Nov 22, 2026

Copy link
Copy Markdown

queue

🛑 The queue request has been cancelled: new commits were pushed

Details

@louistrue pushed to this pull request after queue was requested. Review the new commits and request it again.

@cursor

cursor Bot commented Nov 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot 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)

@louistrue

Copy link
Copy Markdown
Collaborator Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 89b9ba6 at 18:50 UTC

3 h 48 min in the queue, 59 min of it CI.

So far

10 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • check-success=Build + WASM + Rust + Node
  • check-success=Rust tests (feature builds)
  • check-success=Viewer tests (shard 0)
  • github-review-approved · required by GitHub branch protection and GitHub repository ruleset rule main
  • any of · required by GitHub repository ruleset rule main:
    • check-success = @github-actions/Build + WASM + Rust + Node
    • check-neutral = @github-actions/Build + WASM + Rust + Node
    • check-skipped = @github-actions/Build + WASM + Rust + Node
  • any of · required by GitHub repository ruleset rule main:
    • check-skipped = @github-actions/Issue queue
    • check-neutral = @github-actions/Issue queue
    • check-success = @github-actions/Issue queue
  • any of · required by GitHub repository ruleset rule main:
    • check-skipped = @github-actions/PR review signal
    • check-neutral = @github-actions/PR review signal
    • check-success = @github-actions/PR review signal
  • any of · required by GitHub repository ruleset rule main:
    • check-success = @github-actions/parity (in-tree fixtures, committed reference)
    • check-neutral = @github-actions/parity (in-tree fixtures, committed reference)
    • check-skipped = @github-actions/parity (in-tree fixtures, committed reference)
  • any of · required by GitHub repository ruleset rule main:
    • check-success = @github-actions/CLA
    • check-neutral = @github-actions/CLA
    • check-skipped = @github-actions/CLA

Times in UTC · dashboard · how the merge queue works

@github-actions

Copy link
Copy Markdown
Contributor

Claude review - no findings for af95822fe

Reviewed this diff and found nothing to flag.

@github-actions github-actions Bot added the llm-reviewed A review was verified as posted for this PR's head. label Nov 22, 2026
@mergify mergify Bot added the queued label Nov 22, 2026
@github-actions github-actions Bot removed the base-stale Tested against a base that has since moved in a way a whole-tree snapshot cares about (#3726). label Nov 22, 2026
@mergify
mergify Bot merged commit 89b9ba6 into main Nov 22, 2026
86 checks passed
@mergify
mergify Bot deleted the perf/eager-ceiling-streaming-drawing branch November 22, 2026 18:50
@mergify mergify Bot removed the queued label Nov 22, 2026
mergify Bot pushed a commit that referenced this pull request Nov 23, 2026
… (#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.
mergify Bot pushed a commit that referenced this pull request Nov 24, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-reviewed A review was verified as posted for this PR's head. mergify-trial Trial: queue this PR through Mergify batches unqueued Maintainer waiver: this PR may merge without closing a ready issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant