Linora

0508. Incremental marquee query (RectQuery)

Status: Accepted (2026-12-01). Changes packages/engine (query.ts, RenderScene.changeVersion) and the editor’s marquee drag. No wire, rule or memory-baseline change.

Context

Every marquee move called queryRect for the whole rect. For a chunk the rect covers, that re-derives the owner of each instance from the doc (ADR 0024: there is no CPU instance copy to read). With 2M shapes under the marquee, that took about 18 ms of a 20 ms move, although only the band the rect swept since the last move could have changed. The frame rule (filterMarquee) then scanned all 2M results again to find frames.

Decision

  1. RectQuery lives for one marquee drag (Engine.rectQuery(), kept in the drag state). Per chunk it keeps the rect clipped to the chunk’s render bounds and the owners found with it.
  2. An update re-derives only chunks whose clipped rect changed and copies the owners of the others. This is exact, not an approximation: a chunk’s instances lie inside its render bounds, so the same clipped rect meets the same instances. Chunks along an edge that did not move, and chunks inside the rect both times, are reused.
  3. Any document change invalidates it. RenderScene.changeVersion is bumped by every change set the sync applies and by every rebuild; a different version or chunk count re-derives every chunk once. Deferred chunks (ADR 0503) are derived from the doc as queryRect does.
  4. Frames are counted per chunk, so the marquee applies its frame rule only when it meets a frame, and gets the frames from the few chunks holding one (frameHandles()) instead of scanning every result.
  5. A node whose instances span chunks is listed once per chunk; select() drops the duplicates.

Alternatives

Consequences