Linora

0504. Chunk insertion instead of tail layouts

Status: Accepted (2026-11-28, EN2). Amends 0502 decision 2 (positions move only in a tail layout).

Context

ADR 0502 laid out the tail of the paint order from the earliest affected position for every create, move (PARENT_INDEX) or text/path growth past its slot. Appends at the end are cheap. Anything in the middle is not: on the 4,000-page site, drawing into the first page, typing into a text near the start, a layers-panel reorder or a drop into a frame each cost ~0.65 s (a re-derive of up to 11M instances). The editor now does these as everyday hand-editing actions (ED1: text tool, frames that adopt layers, canvas and layers-panel drops of up to 1,000 layers, frame resize).

Decision

  1. A move leaves a hole and is inserted again. A moved subtree gets primStart = -1, and its old range is marked for re-derivation (hidden instances, as for deletes). It is then placed like a created subtree.
  2. Insertions per change set. The roots of unlaid runs are found first; a run is consecutive unlaid siblings under a laid-out parent, such as a paste or a drop of many layers into one frame. Each run, and each node that outgrew its slot, is placed in the gap between the laid-out node before it in pre-order and the next one. When the gap is too small, openChunks(q, deficit) opens whole chunks at the chunk of position q:
    • every primStart >= q shifts by k * 1024. That is one linear pass over the per-node array, about 1 ms for 700K nodes. Nodes before the insertion point that sit exactly at q (the root, groups, empty texts) are restored by a walk back in pre-order;
    • chunk metadata from q’s chunk on moves k chunks up (RenderScene.shiftChunks). Big-instance indexes are chunk-relative, so they move as they are;
    • instances, flags and LOD slots move on the GPU (GpuSink.moveChunks): copyBufferSubData through an 8 MB temporary buffer, back to front, since a buffer cannot copy onto itself. The opened chunks are hidden until derived;
    • only q’s chunk and the opened chunks are re-derived; with ADR 0503, visible ones now and the rest later.
  3. Slack. The opened room is deficit + max(32, n/2) instances, rounded up to whole chunks (so at least 1,024). Later keystrokes and drops at the same place re-derive in place with no shift. Typing 300 characters into a text at the start of a 100K-instance doc opened chunks once and never laid out the tail (test).
  4. Fallbacks. More than 8 insertions in one change set (scattered pastes, generators, a drop into many places) take one tail layout from the earliest position; it also compacts holes. A tail shorter than 64 chunks is laid out too (appends at the end, small docs). Generators and bulk creates keep the memoized linear walk (ADR 0502).

Alternatives

Consequences