Linora

Render engine (packages/engine)

Owner: WP-E (EN2 in wave 3). ADRs 0024 (supersedes 0013’s phasing), 0502, 0503-0506, 0004, 0014, 0002, 0501.

Current (after EN2, wave 3)

EN2 kept the E1 design below and changed when and how much is derived:

E1 design (still current)

packages/engine/src/ is a derived cache of the session’s DocCore (ADR 0024, design details in ADR 0502). It holds no CPU copy of instances, flags or LOD quads:

Measured (ADR 0502): engine CPU 7.9 MB for the 4,000-page site (12.5 B/node) and 26.5 MB for 5M shapes (5.6 B/node); client total 0.512x and 0.691x of the baseline. Full rebuild 0.65 s (website) / 0.8 s (5M shapes); a normal edit ~1 ms.

Target

The engine is a derived cache of DocCore (ADR 0024, supersedes 0013’s phasing). It owns GPU buffers and per-chunk metadata and holds no CPU copy of primitive data: the doc’s columns are the render source.

packages/engine/src/
  chunks.ts       per-chunk metadata: render/geometry bounds, LOD groups, big slots, first node handle, dirty bits
  derive.ts       chunk -> instances into a 40 KB scratch: shapes from columns + world offset, text -> glyphs
                  (TextView + bundled metrics), paths -> segments (PointsView), flags from visibility + selection
  docSync.ts      drains doc ChangeSets -> dirty chunks; primStart maintenance; paint-order rebuilds
  query.ts        hit test, marquee, bounds from doc geometry (walk nodes from a chunk's first handle)
  renderer.ts, shaders.ts, font.ts (bundled font atlas), camera.ts, perf.ts

Memory (ADR 0024 tables)

| Per primitive / node | Today | E1 | E2 | |—|—|—|—| | CPU primitive mirror, CPU flags, primitive -> object | 48 B/prim | 0 | 0 | | Object table -> primStart | 12 B/node | 4 B/node | 4 B/node | | Chunk metadata (Float64 -> Float32 in E2) | 2.4 B/prim | 2.4 B/prim (measured 0.16) | 1.4 B/prim (measured 0.08, ADR 0506) | | GPU instance + flags + impostors (unchanged) | 47.4 B/prim | 47.4 B/prim | 47.4 B/prim |

Doc -> engine sync (once per frame, before draw; ADRs 0502-0505)

  1. doc.drainChanges(); if empty, return (idle frames: one compare).
  2. TRANSFORMs: bake on the GPU while positions are still the old ones (ADR 0505), or mark the roots’ subtrees for re-derivation (small, nested, under a rotated parent, or alongside a move).
  3. Deleted handles and moved subtrees: their chunks are re-derived (hidden holes), and moved subtrees lose their positions.
  4. Changed handles: mark their chunks dirty (GEOMETRY of a container marks its subtree range; TEXT re-lays the node). Nodes whose bounds may move are queued for widening (ADR 0503).
  5. Created nodes, moved subtrees and nodes that outgrew their slot are placed: appends and short tails by a tail layout, up to 8 insertions by opening chunks in place (ADR 0504), more by one tail layout.
  6. processDirty(view, budget): widen queued nodes’ chunks; flag passes (selection, remote slots); derive the visible dirty chunks within the frame budget; the rest in idle callbacks.

Worst case: a paste into more than 8 places, or undo of a large scattered delete, lays out the tail (~0.4 s for 11M instances). Normal edits touch a few chunks (~40 us each); a 10K-node remote batch costs <= 4 ms in its frame.

Multiplayer rendering

Phases

How it protects the baseline

GPU buffers, shaders, chunking, LOD and the drag preview are unchanged, so fps and worst-zoom GPU time are unchanged. Derivation is O(dirty chunks) and skipped when idle; drags stay GPU-only locally and remotely. Every change runs npm run bench (the interleaved before/after gate of ADR 0015: median fps within 5%, headless worst-zoom GPU warn above +10%, fail above +20%), npm run bench -- --memory, and node tools/bench/parity.ts for refactors that must not change behaviour; the absolute worst-zoom GPU budget (<= 3.6 ms, headed) is checked at each milestone.

Targets (WP-E acceptance)