Skip to main content

Module diff

Module diff 

Source
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:

  1. Iterate y from 0 to height
  2. Fast-path skip rows where the full slice is equal
  3. For changed rows, scan in coarse blocks and skip unchanged blocks
  4. 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 run

Structs§

BufferDiff
The diff between two buffers.
ChangeRun
A contiguous run of changed cells on a single row.
TileDiffBuilder
Reusable builder for tile counts and SAT.
TileDiffConfig
Configuration for tile-based diff skipping.
TileDiffInput
Inputs required to build a tile diff plan.
TileDiffPlan
Successful tile build with reusable buffers.
TileDiffStats
Summary statistics from building a tile SAT.
TileParams
Tile parameters derived from the current buffer dimensions.

Enums§

TileDiffBuild
Result of a tile build attempt.
TileDiffFallback
Reason the tile path fell back to a non-tile diff.