szn

Bug 481 — Full O(rows×cols) diff scan every dirty frame

481. No row-granular skipping in the render diff

Severity: MEDIUM (performance) Status: ✅ FIXED Files: src/server/render.zig:483-651, src/grid.zig:58-62

Problem

renderContent always iterates all w × h cells, comparing each against last_cells — even when only one row changed. On an 80×24 terminal that’s ~1920 comparisons/frame; on a 200×60 display ~12000; and the pane merge stage (renderAll, render.zig:183-249) does the same for every dirty pane.

GridLine has a dirty: bool field with doc note that “no production code reads this yet” (grid.zig:58-62), so the flag carries tested copy semantics (see #477 “Deliberately kept”) but gives the render loop no skip benefit.

Proposed Fix

Make row dirtiness drive the diff: when scrolling/editing, mark only affected GridLines dirty in the pane screen; the render loop skips rows whose line is not dirty (a per-line cell-hash check for the ones that are). This turns the diff from O(rows × cols) into O(changed_rows × cols) in the common case (single-line cursor advance, one status-cell change).

The scroll-aware mapping of the dirty flag was called out in #477 as the reason it was left unused — this bug is that follow-up, scoped to line-granular skipping.

Resolution

Wired GridLine.dirty into the render pipeline as the line-granular signal, using the comparison-based mapping #477 flagged as missing:

Tests: a direct renderContent second frame re-emits only the changed row, and a two-frame renderAll against a persistent merged screen + last_cells repaints row 5 without re-emitting row 0’s unchanged text.

Verified: zig build test -Doptimize=ReleaseFast — 1012/1012 tests pass.