Skip to main content

Module snapshot

Module snapshot 

Source
Expand description

DocumentSnapshot – immutable view of a document at one committed point in time (DESIGN.md §5.6.8).

Renderers read every frame through one arc_swap::ArcSwap::load per visible document. The returned Arc<DocumentSnapshot> lives for the entire frame; all subsequent text / metadata reads go through that Arc – no actor round-trip, no lock contention.

§Snapshot fields

v1 ships the subset the TUI renderer actually consumes. Future commits will fold in:

  • selections: Arc<SelectionSet> – when multi-cursor lands (today the App holds a single per-pane cursor).
  • syntax: Option<Arc<SyntaxSnapshot>> – when the syntax cache moves into the actor.
  • decorations: Arc<DecorationLayer> – when the decoration layer (§5.6.2) is built.
  • layout: Option<Arc<LayoutCacheSnapshot>> – shaped buffers only; not relevant for the TUI.

All of these are Arc-cloned per snapshot. A snapshot’s memory cost is independent of buffer size: ~6 Arc words plus the changed-fragment cost of the underlying immutable structures.

§Publish discipline

The actor (and only the actor) writes to the published cell via PublishedSnapshot::store. The runtime layer keeps that method pub(crate) so external callers can’t forge a snapshot. Renderers / readers use PublishedSnapshot::load.

Structs§

DocumentSnapshot
One immutable snapshot of a document. Cheap to clone (every non-trivial field is already Arc-shareable internally; Buffer wraps a ropey::Rope whose interior is a B-tree of Arcs, so cloning is O(log n) with no heap allocation in the common case).
PublishedSnapshot
Single-writer multi-reader cell holding the current DocumentSnapshot. The actor stores; everyone else loads.
SnapshotCache
Per-thread cached reader for a PublishedSnapshot.