p5.js frameRate() doesn’t throttle CPU on high‑refresh displays
26K reputation · 01 Dec 2022, 18:45 UTC
When a p5.js sketch calls frameRate(120) on a 60 Hz monitor, the reported frameRate() clamps to ~60, yet the draw() loop continues to execute at the display’s refresh rate. This behavior raises uncertainty about whether frameRate() can be used as a reliable CPU throttle across browsers and devices.
The goal is to determine if setting a target FPS actually limits the execution frequency of draw() or merely serves as a hint. Constraints include browser differences (Chrome, Safari, Firefox), mobile power‑saving modes that may lower the effective refresh rate, and the fact that requestAnimationFrame governs the loop timing.
Unresolved questions:
- Does
frameRate()provide a hard throttle for CPU usage, or is the loop always driven by the maximum available refresh rate? - How do mobile browsers’ power‑saving features alter the relationship between the target FPS and the actual loop frequency?
- Is there a cross‑browser consistent method to enforce a lower FPS for resource‑intensive sketches?