Skip to content
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

src,lib: optimize nodeTiming.uvMetricsInfo #55614

Closed
wants to merge 4 commits into from

Conversation

RafaelGSS
Copy link
Member

$ node benchmark/compare.js --old ./node-without --new ./node-with --filter "nodetiming" perf_hooks > res.out && node-benchmark-compare res.out
[00:00:43|% 100| 1/1 files | 60/60 runs | 3/3 configs]: Done
                                                               confidence improvement accuracy (*)    (**)   (***)
perf_hooks/nodetiming-uvmetricsinfo.js events=1 n=1000000            ***    467.03 %      ±12.50% ±16.82% ±22.27%
perf_hooks/nodetiming-uvmetricsinfo.js events=1000 n=1000000         ***    479.78 %      ±11.29% ±15.17% ±20.04%
perf_hooks/nodetiming-uvmetricsinfo.js events=10000 n=1000000        ***    486.76 %       ±9.85% ±13.23% ±17.46%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 3 comparisons, you can thus expect the following amount of false-positive results:
  0.15 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.03 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

@RafaelGSS RafaelGSS added performance Issues and PRs related to the performance of Node.js. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Oct 31, 2024
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 31, 2024
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.45%. Comparing base (c63255b) to head (4df0ff2).
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55614      +/-   ##
==========================================
+ Coverage   88.43%   88.45%   +0.01%     
==========================================
  Files         654      654              
  Lines      187662   187751      +89     
  Branches    36117    36149      +32     
==========================================
+ Hits       165962   166066     +104     
+ Misses      14938    14937       -1     
+ Partials     6762     6748      -14     
Files with missing lines Coverage Δ
lib/internal/perf/nodetiming.js 94.28% <100.00%> (+0.23%) ⬆️
src/node_perf.cc 86.44% <100.00%> (-0.40%) ⬇️

... and 43 files with indirect coverage changes

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@RedYetiDev RedYetiDev added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 31, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

src/node_perf.cc Show resolved Hide resolved
@lemire
Copy link
Member

lemire commented Oct 31, 2024

@RafaelGSS

Why is this PR faster?

You create an array from C++, return it to JavaScript, then you convert the array into an object.

Previously, it just returned an object.

What is the catch?

@RafaelGSS
Copy link
Member Author

@lemire The simple answer is: creating an object and transferring from C++ to is costly. Instead of returning just arraysize of 3 uint64_t an object requires allocation of each field value (for instance, event_label) as well as the object structure

In my experience, anything that is sent from C++ to JS (and vice versa) is costly and when you reduce the object size you very often get a performance gain.

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.

Just change the initial commit message, I think is not reflecting the current changes.

@lemire
Copy link
Member

lemire commented Oct 31, 2024

@RafaelGSS

The simple answer is: creating an object and transferring from C++ to is costly. Instead of returning just arraysize of 3 uint64_t an object requires allocation of each field value (for instance, event_label) as well as the object structure

This makes sense, but isn't there a design issue in the first place in the fact that a performance sensitive function (in JavaScript) returns an object?

@RafaelGSS RafaelGSS removed the needs-ci PRs that need a full CI run. label Nov 1, 2024
RafaelGSS added a commit that referenced this pull request Nov 1, 2024
PR-URL: #55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
RafaelGSS added a commit that referenced this pull request Nov 1, 2024
PR-URL: #55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
@RafaelGSS
Copy link
Member Author

Landed in 9b6cea6...d83e9fa

@RafaelGSS RafaelGSS closed this Nov 1, 2024
@RafaelGSS
Copy link
Member Author

This makes sense, but isn't there a design issue in the first place in the fact that a performance sensitive function (in JavaScript) returns an object?

Maybe... but I believe this falls more on the V8 side than the Node.js one. I haven't investigated that communication closely so I might not be able to answer it with precision.

RafaelGSS added a commit that referenced this pull request Nov 1, 2024
PR-URL: #55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
RafaelGSS added a commit that referenced this pull request Nov 1, 2024
PR-URL: #55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
PR-URL: nodejs#55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
louwers pushed a commit to louwers/node that referenced this pull request Nov 2, 2024
PR-URL: nodejs#55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
PR-URL: nodejs#55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
tpoisseau pushed a commit to tpoisseau/node that referenced this pull request Nov 21, 2024
PR-URL: nodejs#55614
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[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. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants