Skip to main content

Module pane_persistent

Module pane_persistent 

Source
Expand description

Prototype: persistent / versioned PaneTree with structural sharing.

This module is the spike deliverable for bead bd-1k7ek.5. It answers a single strategic question: does a persistent (structurally shared) pane tree buy enough asymptotic value — specifically replay-free O(1) undo/redo — to justify its complexity and memory footprint versus the checkpointed PaneInteractionTimeline replay path?

§Design

The canonical PaneTree stores nodes in a flat BTreeMap<PaneId, PaneNodeRecord> with explicit parent pointers. That shape is excellent for O(1) id lookup but is not naturally persistent: cloning the whole map to snapshot a version is O(nodes), and the timeline therefore recovers historical states by replaying operations forward from the nearest checkpoint.

VersionedPaneTree instead represents the tree as an immutable tree of Arc<PersistentNode>. A structural change produces a new root by path-copying: only the nodes on the root→target path are re-allocated; every off-path subtree is reused by an Arc clone (a refcount bump). A PaneVersionStore keeps a Vec of version roots plus a cursor, so undo and redo are pure index moves — no clone, no validation, no replay.

Parent links are intentionally absent from PersistentNode. A node that knew its parent could not be shared between two versions (or two positions), so parents are reconstructed during VersionedPaneTree::to_pane_tree. This is the property that makes structural sharing possible at all.

§Scope (prototype simplifications)

  • Native path-copying covers SetSplitRatio, SplitLeaf, CloseNode, and SwapNodes — i.e. the resize, create, destroy, and rearrange shapes. These exercise in-place mutation, id-allocating insertion, sibling-promoting removal, and two-path rebuild.
  • MoveSubtree and NormalizeRatios use a rebuild fallback: flatten to a canonical PaneTree, apply the certified conservative operation, and rebuild the persistent tree. This guarantees total semantic parity for the differential oracle at the cost of zero sharing for those (rare) operations.
  • The path-copy search is O(nodes) (no id→path index). A production version would maintain a positional index for O(depth) location. The headline win (O(1) version navigation) does not depend on this.

Every native operation is proven byte-identical to PaneTree::apply_operation_conservative over lockstep histories in tests/pane_persistent_equivalence.rs.

Structs§

PaneVersionRetention
Deterministic retained-memory byte model for a PaneVersionStore.
PaneVersionStore
A history of pane-tree versions with replay-free undo/redo.
PaneVersioningReport
Structural-sharing and memory-retention diagnostics for a PaneVersionStore.
VersionedPaneTree
One immutable version of a pane tree.

Enums§

PersistentApplyError
Failure from VersionedPaneTree::apply_operation.
PersistentApplyStrategy
Which application strategy the prototype uses for a given operation.
PersistentNode
Immutable persistent pane node.