Skip to main content

Grid Mode v2: 5-Tier Architecture

Grid Mode v2 combines native VTE parsing with xterm.js WebGL rendering to achieve significant CPU reduction compared to standard xterm.js.

Performance Comparison

The 5-Tier Architecture

The five processing tiers (1–5) sit above the PTY data source (Tier 0). Tier 0 is the input stream itself, not a processing stage — the five tiers below are the stack that transforms raw bytes into rendered glyphs.

Tier 2: ACK-Based Flow Control

The key innovation that prevents crashes during high-output scenarios (LLM streaming, cat large_file).

The Problem

Without flow control:
  • LLM streaming outputs bulk data rapidly
  • Each line triggers DOM reflow
  • Browser crashes or freezes

The Solution

Consumer-driven backpressure:

Key Properties

Note: ACK is sent at RAF callback start, BEFORE inject(). This provides processing-slot backpressure, not frame-level render synchronization. The ~15ms gap between ACK and actual render is a deliberate trade-off to prevent GridWorker blocking.

Tier 3: Cell Format Conversion

Grid Mode v2 converts between two different cell representations:

Native Cell Structure

xterm.js BufferLine Format

Bit-Packing Format

Tier 4: Direct Buffer Injection

Instead of using term.write(), we inject directly into xterm’s internal buffer:
MonoTerm uses _renderRows() for synchronous rendering instead of the async refresh() API. See Synchronous Rendering.

Why Not term.write()?

Epoch-Based Size Synchronization

Prevents race conditions during resize:

Architecture Benefits

The key advantage is bypassing the JavaScript VTE parser entirely, using a native Rust implementation instead.

Key Components