The baseline applyView re-filters + re-sorts the entire id list on every
change — O(n) per update. For large lists this is the gap vs TanStack DB's
differential-dataflow live queries.
This maintains a derived, sorted result and updates it for a SINGLE entity
change in O(log n): binary-search the entity's current position, decide
membership via the filter, and insert / remove / reposition. No full
re-derivation. Result is byte-identical to applyView for the same inputs
(correctness parity is asserted in tests).
Design choice: a hand-rolled dirty-tracking index rather than adopting d2ts
(0.1.x, pre-production) — same acceptance bar (sub-linear single-row update),
far lower dependency risk. The differential engine can replace the internals
later behind this same class without an API change.
view/incremental.ts — G3 parity: incremental view maintenance.
The baseline
applyViewre-filters + re-sorts the entire id list on every change — O(n) per update. For large lists this is the gap vs TanStack DB's differential-dataflow live queries.This maintains a derived, sorted result and updates it for a SINGLE entity change in O(log n): binary-search the entity's current position, decide membership via the filter, and insert / remove / reposition. No full re-derivation. Result is byte-identical to
applyViewfor the same inputs (correctness parity is asserted in tests).Design choice: a hand-rolled dirty-tracking index rather than adopting d2ts (0.1.x, pre-production) — same acceptance bar (sub-linear single-row update), far lower dependency risk. The differential engine can replace the internals later behind this same class without an API change.