Skip to content

benchmark: add calibrate-n script #59186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RafaelGSS
Copy link
Member

benchmark: add calibrate-n script

This script should help identify the best N
when creating/updating benchmarks

It's not new that our benchmark suite takes a huge amount to conclude. I have experienced that myself while writing the State of Node.js Performance 2023 and 2024.

With the help of #59174, I have measured how long it takes to conclude (of course, on my personal machine). This resulted in

image

Full source in: https://docs.google.com/spreadsheets/d/17iZuGR57r7ap4hFG8Tdz5Q-A7oV0cwM4MQW4q5bHA0U/edit?usp=sharing.

The problem is that some benchmarks contain a lot of configurations and an arbitrary N(the number of iterations we run between bench.start() and bench.end(n)). That said, I wrote a calibrate-n.js scripts that measure an "ideal" N for each benchmark file, taking into consideration the following constraints:

  • CV (Coefficient of Variation) less than 5% - default to 30 runs to each configuration
  • Overall CV (between all configurations) is less than 10%

This should help benchmark files to find the lowest N with the lowest variance and thus reduce all benchmark suite time. I'll be opening some PRs during the week, changing the N of some benchmarks.

This script should help identify the best N
when creating/updating benchmarks

Signed-off-by: RafaelGSS <[email protected]>
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/tsc

RafaelGSS added a commit to RafaelGSS/node that referenced this pull request Jul 23, 2025
According to nodejs#59186 this
benchmark file takes 6 hours to complete a full benchmark/compare.js
script (60 runs in total) and this regression tests unrealitics to do
between Node.js releases. By using calibrate-n scripts I could find
a better N also ajusting some bench configs. e.g: avoid dead code
elimination by V8.
@RafaelGSS RafaelGSS added the benchmark Issues and PRs related to the benchmark subsystem. label Jul 23, 2025
Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

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

Awesome tool

@RafaelGSS RafaelGSS added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 25, 2025
@H4ad
Copy link
Member

H4ad commented Jul 25, 2025

I was thinking about this, it will be a good sanity check to get an old PR with perf improvements with the benchmark percentages and then checkout and run this tool to change the parameters to see what we will have in terms of percentages of improvements with the new parameters.

@RafaelGSS
Copy link
Member Author

RafaelGSS commented Jul 25, 2025

I was thinking about this, it will be a good sanity check to get an old PR with perf improvements with the benchmark percentages and then checkout and run this tool to change the parameters to see what we will have in terms of percentages of improvements with the new parameters.

That only works if:

  • We checked out to the same state as the "perf improvement PR"
  • Use the same Node.js version
  • Use the same environment where the initial benchmark was created

So, it's a bit impractical. This tool was created as an attempt to find the good N as most benchmarks is using a N too big. So, in theory, it won't change much.

nodejs-github-bot pushed a commit that referenced this pull request Jul 25, 2025
According to #59186 this
benchmark file takes 6 hours to complete a full benchmark/compare.js
script (60 runs in total) and this regression tests unrealitics to do
between Node.js releases. By using calibrate-n scripts I could find
a better N also ajusting some bench configs. e.g: avoid dead code
elimination by V8.

PR-URL: #59187
Refs: #59186
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
aduh95 pushed a commit that referenced this pull request Jul 25, 2025
According to #59186 this
benchmark file takes 6 hours to complete a full benchmark/compare.js
script (60 runs in total) and this regression tests unrealitics to do
between Node.js releases. By using calibrate-n scripts I could find
a better N also ajusting some bench configs. e.g: avoid dead code
elimination by V8.

PR-URL: #59187
Refs: #59186
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. benchmark Issues and PRs related to the benchmark subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants