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: do less work in insert #27345

Closed
wants to merge 3 commits into from

Conversation

@apapirovski
Copy link
Member

apapirovski commented Apr 22, 2019

Most of the code in insert is only applicable to scheduling non-timers or re-scheduling timers. We can skip most of it in the case of setTimeout, setInterval & setUnrefTimeout.

Second commit fixes a long-standing bug with refresh in cases where it's triggered after the timer already ran its course. Prior to this the refreshed timer would end up always being unrefed, even when it was previously refed.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

lib/internal/timers.js Outdated Show resolved Hide resolved
lib/internal/timers.js Outdated Show resolved Hide resolved
@apapirovski apapirovski force-pushed the apapirovski:patch-timers-perf branch from a1797a8 to 6d93383 Apr 22, 2019
@apapirovski

This comment has been minimized.

Copy link
Member Author

apapirovski commented Apr 22, 2019

@Fishrock123 I've updated with some significant changes in the second commit. There was a bug with refresh that is now fixed and there's a test case provided. (Found it because I was trying to think through and address your comment re: replacing the schedule call in interval branch.)

@Fishrock123 Fishrock123 self-requested a review Apr 22, 2019
@nodejs-github-bot

This comment has been minimized.

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Apr 24, 2019

Benchmark with the latest code: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/356/

Results with any significant change:


                                                             confidence improvement accuracy (*)    (**)   (***)
timers/immediate.js type='clear' n=5000000                          ***     19.14 %       ±2.12%  ±2.80%  ±3.60%
timers/immediate.js type='depth' n=5000000                            *      0.83 %       ±0.73%  ±0.96%  ±1.23%
timers/set-immediate-depth-args.js n=5000000                          *     -0.92 %       ±0.78%  ±1.03%  ±1.32%
timers/timers-cancel-unpooled.js direction='end' n=1000000            *     15.14 %      ±12.87% ±16.98% ±21.81%
timers/timers-depth.js n=1000                                         *      0.06 %       ±0.05%  ±0.07%  ±0.09%
timers/timers-insert-unpooled.js direction='end' n=1000000          ***     24.38 %       ±3.03%  ±4.01%  ±5.15%
timers/timers-timeout-nexttick.js n=50000                            **     -4.00 %       ±2.41%  ±3.18%  ±4.08%
timers/timers-timeout-unpooled.js n=1000000                         ***     -4.59 %       ±2.62%  ±3.45%  ±4.44%
@nodejs-github-bot

This comment has been minimized.

Copy link
Member

Fishrock123 left a comment

I'm not a particular fan of how this makes [kRefed] always be behind _destroyed. Seems like we are unnecessarily adding more "timer is alive or not" dependence to another semi-private property.

Is that required to be part of these changes?

lib/timers.js Show resolved Hide resolved
@Fishrock123

This comment has been minimized.

Copy link
Member

Fishrock123 commented May 10, 2019

@apapirovski thoughts?

@apapirovski

This comment has been minimized.

Copy link
Member Author

apapirovski commented May 30, 2019

@Fishrock123 Your comment is fair. Let's discuss in person at the summit. Didn't have time for the past month to think about this but will probably try to wrap up this PR in the next two days.

@apapirovski apapirovski force-pushed the apapirovski:patch-timers-perf branch from 6d93383 to 28dff83 May 31, 2019
@Fishrock123

This comment has been minimized.

Copy link
Member

Fishrock123 commented Jun 28, 2019

@apapirovski good to merge?

@apapirovski

This comment has been minimized.

Copy link
Member Author

apapirovski commented Jun 28, 2019

@Fishrock123 yeah, should be. I’ll confirm this weekend and do it if so.

@Trott Trott force-pushed the nodejs:master branch from 1ecc406 to 49cf67e Sep 17, 2019
apapirovski added 3 commits Apr 22, 2019
Most of the code in insert is only applicable to scheduling
non-timers or re-scheduling timers. We can skip most of it
in the case of setTimeout, setInterval & setUnrefTimeout.
Expired timers were not being refresh correctly and
would always act as unrefed if refresh was called.
@apapirovski apapirovski force-pushed the apapirovski:patch-timers-perf branch from 28dff83 to d249fc2 Dec 13, 2019
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

Copy link

nodejs-github-bot commented Dec 14, 2019

@Trott
Trott approved these changes Dec 14, 2019
@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Dec 15, 2019

@apapirovski the latest benchmark results do not indicate a big difference at all and these are the only three benchmarks that seemed to have any significance:

01:16:52  timers/timers-depth.js n=1000                                       ***      0.71 %       ±0.19%  ±0.25%  ±0.32%
01:16:52  timers/timers-insert-unpooled.js direction='end' n=1000000            *     -2.55 %       ±2.40%  ±3.17%  ±4.07%
01:16:52  timers/timers-timeout-pooled.js n=10000000                           **     -5.74 %       ±4.14%  ±5.46%  ±7.02%
@Fishrock123

This comment has been minimized.

Copy link
Member

Fishrock123 commented Dec 15, 2019

I think this change aims more to reduce potential edge-cases than desiring a perf impact?

@Fishrock123

This comment has been minimized.

Copy link
Member

Fishrock123 commented Dec 16, 2019

Aside form an extra function closure the only thing I can think of is the coalescing boolean checks...

@Trott

This comment has been minimized.

Copy link
Member

Trott commented Dec 18, 2019

Should this be squashed into one commit or two? If two, which commit should the fixup commit go with?

@Trott

This comment has been minimized.

Copy link
Member

Trott commented Dec 21, 2019

Should this be squashed into one commit or two? If two, which commit should the fixup commit go with?

@apapirovski ^^^^^^^^

BridgeAR added a commit that referenced this pull request Dec 25, 2019
Most of the code in insert is only applicable to scheduling
non-timers or re-scheduling timers. We can skip most of it
in the case of setTimeout, setInterval & setUnrefTimeout.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit that referenced this pull request Dec 25, 2019
Expired timers were not being refresh correctly and
would always act as unrefed if refresh was called.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Dec 25, 2019

@Trott the fixup is for the second commit. I went ahead and landed it in two commits.

Landed in 0b89761, 1fab8a9 🎉

@BridgeAR BridgeAR closed this Dec 25, 2019
BridgeAR added a commit that referenced this pull request Jan 3, 2020
Most of the code in insert is only applicable to scheduling
non-timers or re-scheduling timers. We can skip most of it
in the case of setTimeout, setInterval & setUnrefTimeout.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit that referenced this pull request Jan 3, 2020
Expired timers were not being refresh correctly and
would always act as unrefed if refresh was called.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
targos added a commit that referenced this pull request Jan 14, 2020
Most of the code in insert is only applicable to scheduling
non-timers or re-scheduling timers. We can skip most of it
in the case of setTimeout, setInterval & setUnrefTimeout.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos added a commit that referenced this pull request Jan 14, 2020
Expired timers were not being refresh correctly and
would always act as unrefed if refresh was called.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos added a commit that referenced this pull request Jan 14, 2020
Most of the code in insert is only applicable to scheduling
non-timers or re-scheduling timers. We can skip most of it
in the case of setTimeout, setInterval & setUnrefTimeout.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos added a commit that referenced this pull request Jan 14, 2020
Expired timers were not being refresh correctly and
would always act as unrefed if refresh was called.

PR-URL: #27345
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.