Skip to main content
OpenTUI is built with performance in mind, featuring a native Zig core that powers efficient terminal rendering. This guide covers performance optimization techniques, benchmarking tools, and FPS targets.

Performance Architecture

OpenTUI’s performance comes from its multi-layered architecture:
  • Native Zig Core - Low-level rendering operations in Zig for maximum speed
  • FFI Layer - Efficient bridge between TypeScript and native code
  • Optimized Buffers - Zero-copy buffer management for rendering
  • Smart Diffing - Only renders what changed between frames

FPS Targets

OpenTUI aims for smooth 60 FPS rendering in terminal applications:

Target Frame Times

  • 60 FPS: 16.67ms per frame (recommended)
  • 30 FPS: 33.33ms per frame (acceptable for less interactive apps)
  • 120 FPS: 8.33ms per frame (only for high-performance terminals)

Built-in Performance Monitoring

Debug Overlay

Toggle the debug overlay to see real-time performance metrics:
The overlay shows:
  • Current FPS
  • Frame time (min/max/average)
  • Render buffer statistics
  • Memory usage

Programmatic Stats

Access performance stats in your code:

Memory Snapshots

Monitor memory usage over time:

Benchmarking Tools

OpenTUI includes comprehensive benchmarking utilities for measuring performance.

Native Benchmarks

Run Zig-level benchmarks to test core operations:
This runs benchmarks for:
  • UTF-8 processing and grapheme clustering
  • Text buffer operations
  • Rope data structure performance
  • Editor view rendering
  • Styled text processing

TypeScript Benchmarks

Benchmark the FFI layer and JavaScript integration:
This runs the NativeSpanFeed benchmark suite with different scenarios:
  • Quick: Fast smoke test
  • Default: Standard benchmark run
  • Large: Stress test with large data
  • All: Comprehensive benchmark

Renderer Benchmark

Test 3D rendering performance:
Options:
  • --duration <ms> - Duration per scenario in milliseconds
  • --output <path> - Save results to JSON file
  • --debug - Enable debug mode with culling stats
  • --no-culling - Disable frustum culling for testing
Benchmarks three scenarios:
  1. Single Fast Cube - Baseline rendering performance
  2. Multiple Moving Cubes - Multi-object rendering
  3. Textured Cubes - Complex material and lighting

Optimization Techniques

1. Minimize Render Updates

Only update components when necessary:

2. Batch Updates

Group related changes together:

3. Use Z-Index Wisely

Proper z-index ordering reduces unnecessary redraws:

4. Limit Complex Operations

Avoid expensive operations in the render loop:

5. Optimize Large Lists

Implement virtual scrolling for large datasets:

6. Reduce Console Output

Console logging in TUI apps can impact performance:
Or in code:

Native Rendering Options

Alternate Screen Buffer

Use the alternate screen buffer for better performance:

Threading

Enable threaded rendering (when supported):
Threading is automatically disabled on Linux due to platform limitations.

Profiling Tips

1. Use Environment Variables

Enable debug modes for profiling:

2. Benchmark Custom Code

Create custom benchmarks for your application:

3. Test on Target Terminals

Performance varies by terminal emulator:
  • Fast: Kitty, Ghostty, WezTerm, Alacritty
  • Medium: iTerm2, Windows Terminal
  • Slow: GNOME Terminal, older terminals

Performance Checklist

  • Enable gatherStats during development
  • Set appropriate targetFps for your use case
  • Minimize unnecessary re-renders
  • Batch related updates together
  • Use z-index for proper layering
  • Avoid heavy computations in render loop
  • Implement virtual scrolling for large lists
  • Profile on target terminal emulators
  • Monitor memory usage over time
  • Test with production-like data volumes

Next Steps

Testing

Learn how to test your TUI applications

Native Zig Core

Understand the native architecture