Expand description
Diff computation between buffers.
The BufferDiff computes the minimal set of changed cells between two
buffers using a row-major scan for optimal cache efficiency.
§Algorithm
Row-major scan for cache efficiency:
- Iterate y from 0 to height
- Fast-path skip rows where the full slice is equal
- For changed rows, scan in coarse blocks and skip unchanged blocks
- Within dirty blocks, compare cells using
bits_eq
This ensures sequential memory access since cells are stored row-by-row. With 4 cells per cache line, the prefetcher can anticipate next access.
§Usage
use ftui_render::buffer::Buffer;
use ftui_render::cell::Cell;
use ftui_render::diff::BufferDiff;
let mut old = Buffer::new(80, 24);
let mut new = Buffer::new(80, 24);
// Make some changes
new.set_raw(5, 5, Cell::from_char('X'));
new.set_raw(6, 5, Cell::from_char('Y'));
let diff = BufferDiff::compute(&old, &new);
assert_eq!(diff.len(), 2);
// Coalesce into runs for efficient emission
let runs = diff.runs();
assert_eq!(runs.len(), 1); // Adjacent cells form one runStructs§
- Buffer
Diff - The diff between two buffers.
- Change
Run - A contiguous run of changed cells on a single row.
- Tile
Diff Builder - Reusable builder for tile counts and SAT.
- Tile
Diff Config - Configuration for tile-based diff skipping.
- Tile
Diff Input - Inputs required to build a tile diff plan.
- Tile
Diff Plan - Successful tile build with reusable buffers.
- Tile
Diff Stats - Summary statistics from building a tile SAT.
- Tile
Params - Tile parameters derived from the current buffer dimensions.
Enums§
- Tile
Diff Build - Result of a tile build attempt.
- Tile
Diff Fallback - Reason the tile path fell back to a non-tile diff.