Skip to main content

The Problem

Traditional terminals send the entire screen every time anything changes.

MonoTerm Solution: Hash-Based Diffing

Each line gets a unique fingerprint (hash). Only lines with changed hashes are transmitted.

How It Works

Each line in the terminal buffer is assigned a 64-bit hash computed from its content:
When comparing frames, MonoTerm only compares hashes: Only lines where hash changed get transmitted.

Hash Algorithm: FNV-1a

MonoTerm uses FNV-1a (Fowler-Noll-Vo), a fast non-cryptographic hash optimized for short strings like terminal lines.

Why FNV-1a?

Key Benefits:
  • Same line = Same fingerprint (deterministic)
  • Fingerprint comparison: Single CPU instruction (O(1))
  • No character-by-character comparison needed!

Line Fingerprint System

MonoTerm maintains a fingerprint for each line, enabling instant change detection.

DiffHint Modes

MonoTerm has four modes based on what changed:
Scenario: Only cursor moved, no content changed
  • Data sent: Cursor position only (~10 bytes)
  • Reduction: 99.98%
  • Action: No buffer update, no render

Smart Comparison Range (2V)

MonoTerm only compares the bottom 2V lines (2× viewport height) for change detection, not the entire buffer.

Why 2V Range?

When Full Mode Triggers

The Safety Rule: Why Exactly 2V?

The 2V window ensures that even when content shifts, we can still detect all changes. When shifts exceed our detection range, we automatically switch to Full mode for safety.

Change Detection Flow

Speed:
  • 80 fingerprint comparisons (for 40-row viewport)
  • Each comparison: single CPU instruction
  • Total: microseconds per frame

Performance Comparison

Hash Comparison vs Character-by-Character

Speedup: 4,800 / 40 = 120x faster comparison!

Real-World Examples

You type: ls -la
  • Total sent: 6 x 1,254 = 7,524 bytes
  • Traditional: 6 x 50,000 = 300,000 bytes
  • Reduction: 97.5%
You run: ls -la in a directory with 10 files
  • Output: 10 lines of file listing
  • Dirty rows: 10 (new lines) + 1 (prompt moved) = 11 rows
  • Mode: Partial (11 < 20 threshold)
  • Data sent: 11 x 1,254 = ~13,794 bytes
  • Traditional: 50,000 bytes
  • Reduction: 72.4%
You run: clear
  • All 40 rows change (cleared + new prompt)
  • Dirty rows: 40 (100%)
  • Mode: Full (40 > 20 threshold)
  • Data sent: 50,000 bytes
This is correct! Full mode is more efficient when everything changed.

True Partial Mode

MonoTerm sends only the changed lines, not just renders them partially.

Before vs After

Results


Frontend: Buffer Reuse


ACK Gate: Flow Control

The ACK mechanism prevents buffer overflow by ensuring the frontend processes each update before receiving the next.

Performance Summary

By Scenario

Overall Reduction


Summary

Technology

  • FNV-1a hash for line fingerprinting
  • 2V range comparison (bottom 80 lines)
  • O(1) fingerprint comparison
  • DiffHint modes: None, Partial, Full, Skip
  • Smart Full mode trigger (buffer/history changes)

Benefits

  • 99.95% data reduction (50KB → 25 bytes)
  • Faster IPC (less data to transfer)
  • Less CPU usage (less data to process)
  • Better for remote connections
  • Lower memory/GC pressure