Performance
TUI.zig is designed for high performance.
Architecture
- Double Buffering: We maintain two screen buffers:
currentandprevious. - Diff-Based Rendering: Each frame, we assume the previous buffer reflects the terminal state. We compare it with the current buffer and ONLY emit ANSI escape sequences for cells that changed.
- Batching: Consecutive changes are batched into fewer write calls.
Optimization Tips
- Don't redraw everything: Return
.ignoredfromhandleEventif state didn't change. - Use
SubScreen: When creating custom widgets, draw into the providedSubScreenwhich handles clipping efficiently. - Avoid Allocations: Pre-allocate buffers where possible. TUI.zig's core rendering loop is allocation-free.
Benchmarks
Rendering a full 1920x1080 terminal (approx 200x60 cells) takes < 1ms on modern hardware.