Linora

0103. Bulk geometry ops: TRANSFORM (relative translate) and SET_GEOMETRY (absolute columns)

Status: Accepted (2026-11-28, DC2; shape agreed with R1 realtime, EN2 engine, ED1 editor). Changes shared/src/ops.ts, codec.ts, doc-api.ts, messages.ts: PROTOCOL_VERSION 3, DOC_RULES_VERSION 3.

Context

Moving a selection writes one SET {x, y} per top-level node: ~19 B per node on the wire, one SetOp (four JS objects) per node in the editor, the sync client and every replica, and a 50K-ops-per-message split. The editor refused moves of more than 200K nodes (ADR 0502). The 5M-shape scene cannot be moved at all.

Decision

  1. TRANSFORM = 6: {ids: Float64Array (strictly ascending), dx, dy}. For every listed node that exists: x = fround(x + dx), y = fround(y + dy), clamped to ±MAX_COORD, -0 stored as +0. dx/dy are parent-space; subtrees follow, being parent-relative.
    • Wire: 6 idlist dx:f64 dy:f64, where idlist is the DELETE id format (1 B per id for consecutive ids).
    • Missing ids are skipped. NODE_MISSING only when none exists (DELETE’s rule), so a move survives concurrent deletes.
    • Stateless: ROOT listed -> ROOT_IMMUTABLE; dx or dy > 2·MAX_COORD (NaN included) -> BAD_VALUE. No per-node kind check: x/y apply to every kind but PAGE, and only ROOT is a PAGE.
    • It is exactly the per-node SETs it replaces (property test, byte-identical snapshots).
  2. SET_GEOMETRY = 7: {ids, x?, y?, w?, h?, rotation?: Float32Array}, absolute values aligned with ids.
    • Wire: 7 idlist cols:u8 (f32 * n) per set bit (1 x, 2 y, 4 w, 8 h, 16 rotation; other bits are a framing error).
    • Each value follows its prop’s SET rules. No columns -> BAD_VALUE. Missing ids are skipped, as for TRANSFORM.
    • It is DocCore’s exact inverse of TRANSFORM, and the editor’s form for bulk resize.
  3. Only IEEE add and Math.fround in the rules. A page-space affine (scale about an anchor, lines keeping their endpoints, text re-measured, paths scaled) would need Math.cos/sin/atan2/hypot. ECMAScript leaves those implementation-approximated, so V8 and JavaScriptCore can differ by an ulp and replicas would diverge. Re-measuring text would also tie DOC_RULES_VERSION to the font metrics. So the editor computes resize results itself and sends them as SET_GEOMETRY (plus per-node SETs for TEXT_SIZING and POINTS). Nodes under rotated parents get one TRANSFORM per distinct local delta.
  4. Relative semantics. Concurrent moves of the same node compose in server order (+10 and +20 give +30). A SET of x and a TRANSFORM are ordered by seq like any two writes.
  5. Inverse and undo.
    • DocCore.apply(..., {inverse: true}) returns the exact inverse: SET_GEOMETRY {x, y} of the old values, sharing ids when every id was live. The sync client reverts pending ops with it.
    • The UndoStack and the MCP helper inverseOfTransform undo a TRANSFORM relatively: TRANSFORM(ids, -dx, -dy), sharing the same ids array. This keeps undo at 1 B per id on the wire, adds no 8 B/node old-value copy to the undo stack, keeps peers’ concurrent moves, and lets the engine GPU-bake it.
    • Relative undo is exact when no coordinate crosses a power of two or zero (integer moves always are). Otherwise it is within one f32 ulp (~8e-6 px at x ~ 100); asserted in test/transform.test.ts.
  6. Change feed. ChangeSet.transforms: {roots: Int32Array, dx, dy}[] lists each TRANSFORM in apply order (EN2). The roots and their descendants are not put in changed for it, so the engine bakes the translation on the GPU and then re-derives whatever changed lists. Roots created in the same drain window are left out; they are in created. SET_GEOMETRY marks its nodes GEOMETRY-changed as usual.
  7. Size bounds (with SR-03). ScanBatch fails framing when one batch holds more than MAX_BATCH_EXTRAS (1,048,576) ids plus block nodes. Server cost stays proportional to message bytes: id ranges were deliberately not run-length encoded, because a few bytes could then expand into 8M ids. The sync client splits oversized TRANSFORM / SET_GEOMETRY ops into id-range chunks at commit.

Measured (node packages/doc/bench/run.ts --only move, 200K top-level nodes of a 1M-shape page, medians of 10, shared M4 Pro)

| Stage | TRANSFORM | 200K SETs {x, y} | |—|—:|—:| | OPS payload | 195 KiB, 1 message (1.00 B/node) | 3,711 KiB, 4 messages (19.0 B/node) | | Editor build + encode | 0.0 + 0.9 ms | 8.1 + 15.5 ms | | Gateway ScanBatch + owner StructIndex.check | 1.6 + 0.0 ms | 10.4 + 8.3 ms | | Author apply (local, with inverse) | 7.3 ms | 51.6 ms | | Replica decode + apply (sequenced) | 1.2 + 6.8 ms | 12.6 + 22.2 ms | | Undo sent | 195 KiB (relative) | 3,711 KiB |

Alternatives

Consequences