From 82001664c5d9897c63b33e65222d72ad181fd460 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Mon, 2 Nov 2026 16:16:40 -0800 Subject: [PATCH] round up timeout delay to avoid waking early In Node, setTimeout is scheduled against libuv's integer-millisecond loop clock and can fire a fraction of a millisecond before performance.now() reaches the target time. The timer then isn't yet due, so it waits another frame (17ms) before firing. Co-Authored-By: Claude Opus 5.5 --- src/timer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timer.js b/src/timer.js index 79cdf10..16d85e3 100644 --- a/src/timer.js +++ b/src/timer.js @@ -101,7 +101,7 @@ function sleep(time) { if (timeout) timeout = clearTimeout(timeout); var delay = time - clockNow; // Strictly less than if we recomputed clockNow. if (delay > 24) { - if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew); + if (time < Infinity) timeout = setTimeout(wake, Math.ceil(time - clock.now() - clockSkew) + 1); if (interval) interval = clearInterval(interval); } else { if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);