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

timers: use ref counts to count timers #41231

Conversation

RaisinTen
Copy link
Contributor

@RaisinTen RaisinTen commented Dec 18, 2021

The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: #41219

Signed-off-by: Darshan Sen darshan.sen@postman.com

cc @mscdex @nodejs/timers

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Dec 18, 2021
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@RaisinTen

This comment has been minimized.

@Trott Trott requested a review from mscdex December 18, 2021 14:19
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@aduh95

This comment has been minimized.

@RaisinTen
Copy link
Contributor Author

The benchmark results look very similar to the results of the revert PR - #41298. I think we should go ahead with this change because the slowdown in timers/timers-breadth-args.js and timers/timers-insert-pooled.js is present in the revert PR too.

@nodejs-github-bot

This comment has been minimized.

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

I left some comments but honestly they're all superfluous because this and the original PR are both doing entirely too much work. Both Timer & Immediate already do their own book-keeping in JS-land for the number of active objects. You just need to export a function that returns refCount & immediateInfo[kRefCount] from internal/timers.js.

lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/node.js Outdated Show resolved Hide resolved
The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: nodejs#41219

Signed-off-by: Darshan Sen <darshan.sen@postman.com>
@RaisinTen RaisinTen force-pushed the timers/use-timerListMap-and-outstandingQueue-to-count-timers branch from 157ced8 to 4446606 Compare December 31, 2021 09:41
@RaisinTen RaisinTen changed the title timers: use timerListMap and outstandingQueue to count timers timers: use ref counts to count timers Dec 31, 2021
@RaisinTen
Copy link
Contributor Author

@apapirovski thanks for the review! I've updated the PR to use refCount and immediateInfo[kRefCount] to count the timers, PTAL.

@nodejs-github-bot

This comment has been minimized.

@RaisinTen
Copy link
Contributor Author

RaisinTen commented Dec 31, 2021

Timers benchmark CI: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/1080/

                                                             confidence improvement accuracy (*)    (**)   (***)
timers/immediate.js type='breadth1' n=5000000                               -1.17 %       ±4.24%  ±5.65%  ±7.38%
timers/immediate.js type='breadth4' n=5000000                        **      6.94 %       ±4.99%  ±6.67%  ±8.76%
timers/immediate.js type='breadth' n=5000000                        ***     19.86 %       ±5.15%  ±6.88%  ±8.98%
timers/immediate.js type='clear' n=5000000                          ***    282.93 %       ±4.54%  ±6.11%  ±8.11%
timers/immediate.js type='depth1' n=5000000                         ***     41.79 %       ±1.93%  ±2.58%  ±3.38%
timers/immediate.js type='depth' n=5000000                          ***     41.20 %       ±1.26%  ±1.67%  ±2.17%
timers/set-immediate-breadth-args.js n=5000000                              -0.07 %       ±4.01%  ±5.35%  ±6.99%
timers/set-immediate-breadth.js n=10000000                                  -1.82 %       ±3.54%  ±4.71%  ±6.15%
timers/set-immediate-depth-args.js n=5000000                        ***     39.03 %       ±2.49%  ±3.31%  ±4.31%
timers/timers-breadth-args.js n=1000000                             ***    -12.75 %       ±5.98%  ±8.00% ±10.51%
timers/timers-breadth.js n=5000000                                           2.47 %       ±3.74%  ±4.98%  ±6.50%
timers/timers-cancel-pooled.js n=5000000                            ***    188.38 %      ±24.54% ±32.95% ±43.50%
timers/timers-cancel-unpooled.js direction='end' n=1000000           **     24.24 %      ±15.35% ±20.48% ±26.75%
timers/timers-cancel-unpooled.js direction='start' n=1000000          *      9.86 %       ±8.87% ±11.81% ±15.39%
timers/timers-depth.js n=1000                                               -0.24 %       ±0.47%  ±0.63%  ±0.82%
timers/timers-insert-pooled.js n=5000000                            ***    -17.76 %       ±3.28%  ±4.36%  ±5.68%
timers/timers-insert-unpooled.js direction='end' n=1000000          ***     11.50 %       ±4.24%  ±5.65%  ±7.36%
timers/timers-insert-unpooled.js direction='start' n=1000000        ***     10.90 %       ±3.99%  ±5.31%  ±6.91%
timers/timers-timeout-nexttick.js n=50000                           ***     18.12 %       ±6.26%  ±8.35% ±10.93%
timers/timers-timeout-nexttick.js n=5000000                         ***     70.62 %       ±8.74% ±11.63% ±15.16%
timers/timers-timeout-pooled.js n=10000000                          ***     93.09 %      ±11.97% ±16.06% ±21.16%
timers/timers-timeout-unpooled.js n=1000000                         ***     88.09 %      ±14.55% ±19.37% ±25.22%

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for making the change!

@RaisinTen RaisinTen added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed needs-ci PRs that need a full CI run. labels Jan 1, 2022
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Benchmark results look impressive 👏

@RaisinTen RaisinTen added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 2, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 2, 2022
@nodejs-github-bot nodejs-github-bot merged commit 64cc066 into nodejs:master Jan 2, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 64cc066

@RaisinTen RaisinTen deleted the timers/use-timerListMap-and-outstandingQueue-to-count-timers branch January 2, 2022 15:28
targos pushed a commit that referenced this pull request Jan 14, 2022
The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: #41219

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: #41231
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 31, 2022
The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: #41219

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: #41231
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: nodejs#41219

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: nodejs#41231
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Feb 1, 2022
The additional objects that were getting added and deleted from the
activeTimersMap object were slowing down the rest of the timers code,
so this change falls back to using the ref counts to count the active
timers inside process.getActiveResourcesInfo().

Fixes: #41219

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: #41231
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@danielleadams danielleadams mentioned this pull request Feb 1, 2022
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. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

timers: recent performance regressions
5 participants