Skip to main content

Display Timing System

Monolex uses an adaptive timing system that measures actual WebKit rendering performance and adjusts the entire backend accordingly. This provides optimal efficiency under varying system loads.

Overview

Why Adaptive Timing?

WebKit’s requestAnimationFrame rate varies based on system conditions: Without adaptive timing, the backend would continue operating at 60Hz even when WebKit can only render at 30fps, wasting CPU cycles.

Two Control Layers

Monolex uses two complementary mechanisms to optimize rendering:

Hz Detection (Outer Control)

Controls how often the backend attempts to render:
  • Measures WebKit FPS using requestAnimationFrame
  • Updates effective_hz atomically in Rust
  • All frame-based durations scale automatically

ACK Gating (Inner Control)

Controls whether each emit is allowed:
  • Frontend sends ACK after processing each frame
  • Backend blocks next emit until ACK received
  • Prevents frontend overload

Cost Savings

When Hz drops from 60 to 30: The key insight: both mechanisms produce the same emit rate (~10/sec at 30fps), but Hz detection reduces backend work while ACK gating prevents frontend overload.

Measurement Process

Adaptive Intervals

  • Normal (≥30 fps): Measure every 3 seconds
  • Low (< 30 fps): Measure every 1 second

Self-Regulating System

The timing system creates a natural feedback loop:
This self-regulation prevents the terminal from contributing to system overload.

How It Works

Why Both Are Needed

Key Points

Hz Detection

Controls Rust backend tick rate. Proactive optimization that reduces work before overload.

ACK Gating

Protects frontend from overload. Reactive backpressure that blocks when busy.

Lock-Free

Uses AtomicU32 for thread-safe, lock-free Hz sharing across async tasks.

Self-Regulating

Creates natural feedback loop that prevents terminal from contributing to system load.