Skip to main content

WebKit requestAnimationFrame and Hz Detection

WebKit’s requestAnimationFrame (rAF) is the heartbeat of browser rendering. This document covers how Monolex detects actual display performance and adapts its timing system accordingly.

Architecture Overview

RAF Callback Timing

WebKit calls RAF callbacks at the display’s refresh rate, but actual timing varies:

Hz Detection Flow

FPS Safety Limits

Frame Duration Calculation

System Load Impact

Adaptive Response

When system load increases:
  1. WebKit naturally throttles RAF rate
  2. DisplayTimingManager detects lower fps
  3. Backend adjusts all frame-based timeouts
  4. Fewer IPC calls, larger batches
  5. System maintains stability under load

ProMotion Display Support

Summary

RAF as Heartbeat

WebKit RAF timing reflects actual display performance.

60-Sample Average

Smooth FPS measurement over 60 frames (~1 second).

20-120Hz Range

Minimum 20fps floor, maximum hardware Hz cap.

~4-8ns Cost

Lock-free atomic operations for minimal overhead.