Skip to content

round up timeout delay to avoid waking early - #61

Merged
mbostock merged 1 commit into
mainfrom
mbostock/timeout-ceil
Nov 3, 2026
Merged

mbostock merged 1 commit into
mainfrom
mbostock/timeout-ceil

Conversation

@mbostock

@mbostock mbostock commented Nov 3, 2026

Copy link
Copy Markdown
Member

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. When that happens, wake finds the timer isn’t yet due and waits another frame, so timers with delays over 24ms fire ~17ms late. This rounds the timeout delay up.

This is one of two causes of flaky tests under current Node (e.g. 66.58 should be in range of [40, 60]); the other, tests seeing a now() cached by the previous test, is fixed in #58, which will be rebased onto this once merged. Supersedes #59.

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@mbostock
mbostock merged commit ae57a06 into main Nov 3, 2026
2 checks passed
@mbostock
mbostock deleted the mbostock/timeout-ceil branch November 3, 2026 00:21
mbostock added a commit that referenced this pull request Nov 3, 2026
The timeout delay is now rounded up (#61), adding up to 2ms to the delays
observed by the wake-time tests. Also restore the global setTimeout after
each test, and pass --exit to mocha so that a failing test that leaves an
active timer doesn't hang the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mbostock added a commit that referenced this pull request Nov 3, 2026
* es bundle, pnpm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* isolate tests from cached now()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* allow for rounded-up timeout; don't hang on failure

The timeout delay is now rounded up (#61), adding up to 2ms to the delays
observed by the wake-time tests. Also restore the global setTimeout after
each test, and pass --exit to mocha so that a failing test that leaves an
active timer doesn't hang the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* vitest, eslint 9

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* remove stale test/.eslintrc.json

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* eslint 10, vitest 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* import it from vitest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* eslint config

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* browser globals for src

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* d3-timer alias

* 3.0.2

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant