Back to Hub
ENGINE INTERNALS • MAY 2026

Defeating the 4ms Throttle via AudioWorklet Clocks.

A dark secret of JavaScript performance is that you cannot set a timeout faster than 4 milliseconds. Due to historical battery-saving implementations, if you call setTimeout(fn, 0), the browser artificially delays execution by at least 4ms. For rendering a 120fps Canvas Editor or synchronizing multi-threaded WebAssembly execution, a 4ms margin of error causes visually noticeable frame jitter and micro-stutters.

NitroIDE requires a flawless, un-throttled heartbeat. We achieved this by hijacking the Web Audio API's AudioWorklet to act as an ultra-high-precision, sub-millisecond system clock.

Why Audio Cannot Be Throttled

Browser vendors cannot throttle the Web Audio rendering thread. If they delayed audio processing by even 2ms, users would hear audible clicks, pops, and distortion. The AudioWorklet guarantees absolute, real-time priority at the hardware level, executing its process() function reliably every 128 audio samples (roughly every 2.9 milliseconds at 44.1kHz).

// Inside the AudioWorkletProcessor: The unthrottled heartbeat
class PrecisionClockProcessor extends AudioWorkletProcessor {
  constructor() {
    super();
    this.tickCount = 0;
  }

  process(inputs, outputs, parameters) {
    // This runs with absolute hardware priority every ~2.9ms
    this.tickCount++;
    
    // Alert the main thread or WASM thread via a SharedArrayBuffer
    if (this.tickCount % 3 === 0) {
      Atomics.add(sharedClockBuffer, 0, 1);
      Atomics.notify(sharedClockBuffer, 0);
    }
    
    return true; // Keep the clock alive
  }
}

The Atomics Sync: We map a SharedArrayBuffer between the AudioWorklet and our background WASM compiler threads. The AudioWorklet rapidly increments the value. The WASM thread utilizes Atomics.wait(), instantly waking up the microsecond the clock ticks, completely bypassing the main thread's Event Loop scheduling.

Absolute Determinism

By slaving our rendering and compilation pipelines to the sound card's hardware clock rather than the V8 Event Loop, NitroIDE achieves frame-perfect execution determinism. Animations never drop frames, and AST parsing tasks are scheduled with microsecond precision.

See Perfect Synchronization.

Run a heavy compilation task and watch the UI render at a locked 120fps.

Launch Workspace