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: speed up process.getActiveResourcesInfo() #46014

Conversation

RaisinTen
Copy link
Contributor

@RaisinTen RaisinTen commented Dec 29, 2022

This change reduces the number of calls that were crossing the JS-C++ boundary to 1 and also removes the need for calling Array::New() multiple times internally and ArrayPrototypeConcat-ing the results later on, thus improving performance by 75%!

Refs: #44445 (review)
Signed-off-by: Darshan Sen raisinten@gmail.com


This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: nodejs#44445 (review)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Dec 29, 2022
@aduh95
Copy link
Contributor

aduh95 commented Dec 29, 2022

Benchmark CI: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1280

                                                                                                                            confidence improvement accuracy (*)   (**)  (***)
process/getActiveResourcesInfo.js n=100000 immediatesCount=10000 timeoutsCount=10000 requestsCount=10000 handlesCount=10000        ***     75.23 %       ±4.60% ±6.19% ±8.19%

@aduh95
Copy link
Contributor

aduh95 commented Dec 29, 2022

Benchmark CI(timers): https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1281

Results
                                                             confidence improvement accuracy (*)    (**)   (***)
timers/immediate.js type='breadth' n=5000000                                 0.55 %       ±1.51%  ±2.02%  ±2.63%
timers/immediate.js type='breadth1' n=5000000                               -0.66 %       ±1.90%  ±2.53%  ±3.30%
timers/immediate.js type='breadth4' n=5000000                               -2.26 %       ±4.90%  ±6.52%  ±8.49%
timers/immediate.js type='clear' n=5000000                           **      3.84 %       ±2.51%  ±3.34%  ±4.36%
timers/immediate.js type='depth' n=5000000                          ***      4.91 %       ±2.09%  ±2.81%  ±3.70%
timers/immediate.js type='depth1' n=5000000                                  2.35 %       ±2.66%  ±3.55%  ±4.65%
timers/set-immediate-breadth-args.js n=5000000                               0.08 %       ±4.30%  ±5.72%  ±7.44%
timers/set-immediate-breadth.js n=10000000                                   1.91 %       ±2.16%  ±2.87%  ±3.75%
timers/set-immediate-depth-args.js n=5000000                                 1.23 %       ±2.30%  ±3.06%  ±3.98%
timers/timers-breadth-args.js n=1000000                                     -0.74 %       ±6.10%  ±8.11% ±10.56%
timers/timers-breadth.js n=5000000                                           2.99 %       ±6.06%  ±8.06% ±10.49%
timers/timers-cancel-pooled.js n=5000000                                     3.68 %       ±7.33%  ±9.75% ±12.69%
timers/timers-cancel-unpooled.js direction='end' n=1000000                  -4.24 %      ±10.53% ±14.01% ±18.23%
timers/timers-cancel-unpooled.js direction='start' n=1000000                 0.44 %       ±3.24%  ±4.31%  ±5.61%
timers/timers-depth.js n=1000                                               -0.07 %       ±0.48%  ±0.64%  ±0.85%
timers/timers-insert-pooled.js n=5000000                              *      4.61 %       ±4.39%  ±5.84%  ±7.61%
timers/timers-insert-unpooled.js direction='end' n=1000000                  -0.92 %       ±1.74%  ±2.32%  ±3.02%
timers/timers-insert-unpooled.js direction='start' n=1000000                -0.22 %       ±2.04%  ±2.71%  ±3.53%
timers/timers-timeout-nexttick.js n=50000                                   -0.75 %       ±2.58%  ±3.43%  ±4.48%
timers/timers-timeout-nexttick.js n=5000000                                 -2.15 %       ±5.46%  ±7.27%  ±9.46%
timers/timers-timeout-pooled.js n=10000000                                   2.97 %       ±6.69%  ±8.90% ±11.59%
timers/timers-timeout-unpooled.js n=1000000                                  0.22 %       ±1.68%  ±2.25%  ±2.94%

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

@aduh95 aduh95 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 Dec 29, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 29, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

lib/internal/timers.js Show resolved Hide resolved
Environment* env = Environment::GetCurrent(args);
std::vector<Local<Value>> resources_info;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if you can omit using std::vector for better performance in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions on how you think that can be done?

Refs: nodejs#46014 (comment)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
@RaisinTen RaisinTen added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Jan 2, 2023
lib/internal/timers.js Outdated Show resolved Hide resolved
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@RaisinTen RaisinTen requested a review from aduh95 January 3, 2023 09:12
@RaisinTen RaisinTen added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 3, 2023
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jan 3, 2023
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/46014
✔  Done loading data for nodejs/node/pull/46014
----------------------------------- PR info ------------------------------------
Title      src: speed up `process.getActiveResourcesInfo()` (#46014)
Author     Darshan Sen  (@RaisinTen)
Branch     RaisinTen:src/speed-up-process.getActiveResourcesInfo -> nodejs:main
Labels     c++, lib / src, author ready, needs-ci, commit-queue-squash
Commits    3
 - src: speed up process.getActiveResourcesInfo()
 - lib: explain timeoutInfo
 - lib: update comment
Committers 2
 - Darshan Sen 
 - GitHub 
PR-URL: https://github.com/nodejs/node/pull/46014
Reviewed-By: Antoine du Hamel 
Reviewed-By: Chengzhong Wu 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/46014
Reviewed-By: Antoine du Hamel 
Reviewed-By: Chengzhong Wu 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - lib: update comment
   ℹ  This PR was created on Thu, 29 Dec 2022 14:11:08 GMT
   ✔  Approvals: 2
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/46014#pullrequestreview-1232745904
   ✔  - Chengzhong Wu (@legendecas) (TSC): https://github.com/nodejs/node/pull/46014#pullrequestreview-1233540022
   ✔  Last GitHub CI successful
   ℹ  Last Benchmark CI on 2022-12-29T20:19:51Z: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1281
   ℹ  Last Full PR CI on 2023-01-03T08:15:41Z: https://ci.nodejs.org/job/node-test-pull-request/48821/
- Querying data for job/node-test-pull-request/48821/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/3828266911

@RaisinTen RaisinTen added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jan 3, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 3, 2023
@nodejs-github-bot nodejs-github-bot merged commit e35e893 into nodejs:main Jan 3, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in e35e893

@RaisinTen RaisinTen deleted the src/speed-up-process.getActiveResourcesInfo branch January 3, 2023 10:37
RafaelGSS pushed a commit to RafaelGSS/node that referenced this pull request Jan 17, 2023
This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: nodejs#44445 (review)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: nodejs#46014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Jan 20, 2023
This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: #44445 (review)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: #46014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
@RafaelGSS RafaelGSS mentioned this pull request Jan 20, 2023
juanarbol pushed a commit that referenced this pull request Jan 26, 2023
This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: #44445 (review)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: #46014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
@juanarbol juanarbol mentioned this pull request Jan 28, 2023
juanarbol pushed a commit that referenced this pull request Jan 31, 2023
This change reduces the number of calls that were crossing the JS-C++
boundary to 1 and also removes the need for calling Array::New()
multiple times internally and ArrayPrototypeConcat-ing the results
later on, thus improving performance.

Refs: #44445 (review)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: #46014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
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-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants