Per-cell damage tracking
Redrawing every cell on every animation frame burns CPU and GPU bandwidth when only a prompt line or cursor moved. ghostty-webgpu carries dirty state from libghostty-vt all the way down to GPU byte-range uploads and Canvas or DOM row updates.
You will learn
How dirty state flows from
libghostty-vtintobridge.wasmand each rendererWhich work each backend skips on idle screens, repeated redraws, scrolls, and single-line edits
- How DEC mode 2026 synchronized output prevents torn TUI frames
- How observer APIs expose coherent presented frames
The damage pipeline
Section titled “The damage pipeline”write() / resize / setAppearance() | vlibghostty-vt dirty flags (false / partial / full) | vbridge.wasm rebuilds dirty rows into persistent cell & glyph buffers | vUpload changed byte ranges (WebGPU/WebGL2) or repaint dirty rows (Canvas 2D / DOM) | vEmit submittedFrame / onFrame / onTextA container resize, font metric change, theme or palette change, or GPU device restoration triggers a full rebuild so every cell reflects the new geometry or colors. Everything else goes through the incremental path.
What each backend skips
Section titled “What each backend skips”- Idle frames: When
renderState.update()reports no damage and neither cursor blink nor text blink changed phase, the renderer exits early and submits zero GPU commands. - Repeated identical screens: When a TUI rewrites unchanged panels with the same characters and styles, byte-level diffing against persistent Zig instance records skips redundant uploads. In the November 2026 benchmarks,
repeated-asciiruns at0.20xto0.36xthe CPU of the best competitor. - Full-viewport scrolling: WebGPU and WebGL2 retain physical row slots across full-viewport scrolls and shift them visually via shader row offsets, rebuilding only newly exposed rows. Canvas 2D self-copies unchanged rows via
drawImagewhen device row height is integral. - Single-line edits: Canvas 2D tracks per-row plain-text damage to repaint only the changed horizontal span (plus glyph overhang); GPU backends upload only the modified byte slices of the persistent instance buffer.
Synchronized output (DEC mode 2026) and startup swaps
Modern TUIs wrap multi-line redraws inside CSI ? 2026 h (begin synchronized update) and CSI ? 2026 l (end synchronized update). While mode 2026 is active, ghostty-webgpu continues parsing incoming bytes into libghostty-vt but holds visual presentation until release or safety timeout. That prevents half-drawn frames and also delays any pending Canvas-to-GPU startup swap so the handoff never splits an atomic TUI frame.
Coherent snapshots for overlays and observers
Section titled “Coherent snapshots for overlays and observers”Overlays such as link hit-testing, screen-reader mirrors, and IME caret placement must match the pixels currently displayed rather than bytes parsed five microseconds ago and not yet painted.
terminal.submittedFramereturns immutable metadata (frame,nativeRevision,grid,font,padding,cursor,selection,scrollbar) for the last presented frame (see TerminalSubmittedFrame).terminal.onFrame(({ rows }) => ...)fires with the row indices updated in each submitted frame.terminal.onText(({ frame, rows, rowPatches }) => ...)delivers text patches synchronized with presentation.terminal.refresh(startRow, endRow)marks a row range dirty on demand, andterminal.clearTextureAtlas()flushes cached glyph bitmaps so newly loaded fonts rasterize fresh.
Recap
Idle screens submit zero GPU work; partial edits upload only changed byte ranges or row spans.
Full-viewport scrolls reuse GPU row slots and Canvas self-copies instead of repainting every row.
Read
submittedFrame,onFrame, oronTextwhenever UI overlays need to match what is on screen.