Skip to content

Add benchmarks for node only mode and mock timers.#64097

Open
luanmuniz wants to merge 1 commit into
nodejs:mainfrom
luanmuniz:benchmark-test-runner-only-mock-timers
Open

Add benchmarks for node only mode and mock timers.#64097
luanmuniz wants to merge 1 commit into
nodejs:mainfrom
luanmuniz:benchmark-test-runner-only-mock-timers

Conversation

@luanmuniz

@luanmuniz luanmuniz commented Jun 23, 2026

Copy link
Copy Markdown

Adds another small set of node:test benchmarks for areas listed in #55723.
A continuation of the work I started in #63754
This is a different PR because it brings a different set of attention points, and to keep both PR easy to review.

This PR covers:

  • only mode with --test-only
  • mock.timers.enable()
  • mocked setTimeout
  • mocked setInterval
  • mocked setImmediate
  • mocked scheduler.wait
  • mocked AbortSignal.timeout
  • mocked Date.now()
  • mock.timers.setTime()
  • mock.timers.runAll()

Notes

  1. enable-* test the enable() + reset() instead of just enable. This happens because an error is thrown if enable is called multiple times without reset.
  2. The scheduler.wait mode includes the final Promise.all() inside the measured section. My evaluation was that it was more appropriate to do so than not, since the scheduled waits are promise-based, but I am happy to adjust the structure if reviewers prefer a narrower measure.

Issue found while writing this

TLDR: I found an issue (that doesn't affect this PR) with using setImmediate and runAll together while writing the benchmark; guidance welcome;

While writing the benchmark, I found that setImmediate doesn't work with runAll(). The mocked setImmediate is scheduled with a special -1 time so it runs before zero-delay timers. runAll() computes longestTimer.runAt - this.#now in mock_timers.js:816, which becomes -1, and tick() rejects negative time in mock_timers.js:556.

I would love to open a new PR to fix this issue, but this is beyond my context of how the team working on this operates and what they think would be an appropriate fix. If the person reviewing the PR could provide some guidance on the best way to handle this issue, it would be much appreciated.

This issue doesn't impact this PR, all benchmarks still work with the current code (With tick(0) instead of runAll() for setImmediate).

The only benchmark covers creating selected and non-selected tests when
running with --test-only.

The mock timers benchmark covers enabling timer mocks, setTimeout,
setInterval, setImmediate, scheduler.wait, AbortSignal.timeout,
mocked Date.now(), setTime(), and runAll().

Refs: nodejs#55723
Signed-off-by: Luan Muniz <luan@luanmuniz.com.br>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added benchmark Issues and PRs related to the benchmark subsystem. test_runner Issues and PRs related to the test runner subsystem. labels Jun 23, 2026

for (let i = 0; i < selected; i++) {
test(`selected-${i}`, { only: true }, () => {
avoidV8Optimization = i;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary; it's a clojure. Adding an assert.ok is probably more useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Issues and PRs related to the benchmark subsystem. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants