Expand description
Incremental View Maintenance (IVM) — delta-propagation DAG for derived render state (bd-3akdb.1).
§Overview
IVM maintains computed layouts, styled text, and visibility flags as materialized views updated by deltas only. Instead of full recomputation each frame, changes propagate through a DAG of view operators that transform input deltas into output deltas.
§Architecture
Observable<Theme> Observable<Content> Observable<Constraint>
│ │ │
▼ │ │
┌──────────────┐ │ │
│ StyleView │◄──────────┘ │
│ (resolve) │ │
└──────┬───────┘ │
│ Δ(style) │
▼ │
┌──────────────┐ │
│ LayoutView │◄─────────────────────────────────┘
│ (compute) │
└──────┬───────┘
│ Δ(rects)
▼
┌──────────────┐
│ RenderView │
│ (cells) │
└──────┬───────┘
│ Δ(cells)
▼
BufferDiff → Presenter → Terminal§Delta Representation
Updates are represented as signed tuples: (key, weight, logical_time).
weight = +1: insertion / update (new value replaces old).weight = -1: deletion (key removed from the view).logical_time: monotonic counter for causal ordering.
This is the standard IVM delta encoding from database theory (Chirkova & Yang, “Materialized Views”, §3.1). It composes: applying Δ₁ then Δ₂ is equivalent to applying their union (with cancellation of opposite signs).
§Processing Model
Deltas are processed in topological micro-batches:
- Collect all input changes since last frame (the “epoch”).
- Sort the DAG topologically (pre-computed at DAG build time).
- For each view in topological order:
a. Receive input deltas from upstream views.
b. Apply
apply_delta()to produce output deltas. c. Forward output deltas to downstream views. - The final view emits cell-level deltas consumed by the presenter.
If any view’s delta set exceeds a size threshold (heuristic: > 50% of
the materialized view size), the view falls back to full recomputation
via full_recompute(). This handles the “big change” case efficiently.
§Evidence Logging
Each propagation epoch logs an ivm.propagate tracing span with:
epoch: monotonic epoch counterviews_processed: number of views that received deltasviews_recomputed: number of views that fell back to full recomputetotal_delta_size: sum of delta entry counts across all viewsduration_us: wall-clock time for the entire propagation
An evidence JSONL entry is emitted comparing delta size vs full recompute cost per view, enabling offline analysis of IVM efficiency.
§Fallback
Setting FRANKENTUI_FULL_RECOMPUTE=1 disables incremental processing
and forces full recomputation on every frame. This serves as a baseline
for benchmarking and a safety fallback if IVM introduces bugs.
§Integration with Existing Infrastructure
- DepGraph (ftui-layout): Used for layout-level dirty tracking.
IVM wraps DepGraph as the backing store for
LayoutView. - Observable/Computed (ftui-runtime/reactive): Observable changes feed the IVM input layer. Computed values can be replaced by IVM views for frequently-updated derivations.
- Buffer dirty tracking (ftui-render): RenderView output deltas are translated to Buffer dirty_rows/dirty_spans for the presenter.
- BatchScope (ftui-runtime/reactive): Batched observable mutations naturally align with IVM epochs — one batch = one propagation pass.
Structs§
- CellKey
- Key for render view: identifies a cell position (row, col).
- Cell
Value - Cell value (the output of render computation).
- DagEdge
- An edge in the IVM DAG, connecting an upstream view to a downstream view.
- DagTopology
- The static topology of the IVM DAG.
- Delta
Batch - A batch of delta entries for a single propagation epoch.
- Epoch
Evidence - Evidence record for a single IVM propagation epoch.
- Fallback
Policy - Policy for deciding when a view should fall back to full recomputation.
- Filtered
List View - IvmConfig
- Configuration for the IVM system.
- Layout
Key - Key for layout view: identifies a layout node.
- Layout
Value - Layout result value (the output of layout computation).
- Propagation
Result - The outcome of processing a single view during propagation.
- Resolved
Style Value - Resolved style value (the output of style resolution).
- Style
Key - Key for style view: identifies a widget’s style slot.
- Style
Resolution View - A concrete
IncrementalViewthat resolves styles by merging a base (theme) style with per-widget overrides. - View
Descriptor - Descriptor for a view in the DAG.
- ViewId
- Lightweight handle identifying a view in the IVM DAG.
Enums§
- Delta
Entry - A signed delta entry representing an incremental change.
- View
Domain - The domain of a view in the IVM pipeline.
Traits§
- Incremental
View - The core trait for incremental view maintenance.
Functions§
- fx_hash
- Compute a fast hash of an arbitrary hashable value.