Linora

0107. DELETE inverse: RESTORE blocks per parent

Status: Accepted (2026-12-01). Supersedes point 3 of 0101 for DELETE’s inverse. Changes packages/doc only: no wire, rule or snapshot change (PROTOCOL_VERSION and DOC_RULES_VERSION unchanged).

Context

ADR 0101 made DELETE’s inverse one RESTORE per deleted root, in reverse delete order. Each root’s block was encoded on its own, and the encoder allocated a position map the size of the whole document per block. Deleting 2M selected shapes in the demo therefore allocated and zeroed about 2M x 8 MB: one Delete froze the page for 30 s (28 s in the encoder and the garbage collector).

Undo was quadratic as well whenever other layers sat below the deleted ones under the same parent, as the demo’s Welcome page does. RESTORE links each root under its parent by key, searching from the parent’s last child. Roots restored in reverse order land between those layers and every root restored before them, so each search walked all of them: undoing a delete of 100,000 shapes took 7.6 s, and 2M would take about an hour.

Decision

  1. One RESTORE block per run of roots under the same parent, at most about 10,000 nodes (RESTORE_BLOCK_NODES). A block that encodes larger than MAX_MESSAGE_BYTES / 4 is halved until it fits, so text and points do not push a single op past the 4 MiB message limit. The per-batch node cap (MAX_BATCH_EXTRAS, 1M) is far above what one message carries.
  2. A listed node under another listed node travels in that node’s block and gets no block of its own. Before this was implicit: deleting the ancestor first made the descendant’s id missing.
  3. Roots in sibling order. Within a parent, roots are written in sibling order: id order when it matches, as it does for layers drawn or generated on top, otherwise sorted by key. Blocks are applied in that order, and insertBlock links each root starting from the previous root, so a block of roots between existing siblings is linked in O(n + gaps).
  4. The encoder keeps a path stack instead of a handle-sized position map for parent references: in pre-order a node’s parent is on the path from its root. The bytes are identical.

RESTORE itself is unchanged: the block format already allowed many roots under one parent, and the server checks every node of a block (ADR 0101 point 2).

Alternatives

Consequences