Skip to content

timers: clean up, async integration for unref, simplify clearTimeout #18579

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

Closed

Conversation

apapirovski
Copy link
Contributor

@apapirovski apapirovski commented Feb 5, 2018

Assorted, small changes to timers:

  1. A recent commit removed the usage of the second argument of tryOnTimeout but left the definition in place. Remove it.

  2. It's possible for user-code to flip an existing timeout to be an interval during its execution, in which case the current code would crash due to start being undefined. Fix this by providing a default start value within rearm.

  3. When async hooks integration for Timers was introduced, it was not included in the code for unref'd or subsequently ref'd timers which means those timers only have TIMERWRAP hooks.

  4. Remove dead code from timeout & interval clearing — timer[kOnTimeout] is not something that can exist, as kOnTimeout only exists on TimerWrap.

The first two commits are semver-major as they rely on several prior semver-major PRs, the other two can both go into 8.x & 9.x and I will handle back-porting these sometime later this month.

Benchmark results:

 timers/timers-breadth.js thousands=5000                    -0.49 %       ±3.13%   ±4.13%   ±5.31%
 timers/timers-cancel-pooled.js millions=5          ***   1643.69 %      ±84.28% ±111.55% ±144.05%
 timers/timers-cancel-unpooled.js millions=1        ***    101.54 %       ±9.13%  ±12.06%  ±15.51%
 timers/timers-depth.js thousands=1                         -0.01 %       ±0.09%   ±0.12%   ±0.15%
 timers/timers-insert-pooled.js millions=5                   0.43 %       ±2.05%   ±2.71%   ±3.48%
 timers/timers-insert-unpooled.js millions=1                 0.80 %       ±3.13%   ±4.13%   ±5.30%
 timers/timers-timeout-pooled.js millions=10                -2.38 %       ±4.92%   ±6.49%   ±8.34%
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

timers, test

A recent commit removed the usage of the second argument of
tryOnTimeout but left the definition in place. Remove it.
It's possible for user-code to flip an existing timeout to
be an interval during its execution, in which case the
current code would crash due to start being undefined. Fix
this by providing a default start value within rearm.
When async hooks integration for Timers was introduced, it was
not included in the code for unref'd or subsequently ref'd
timers which means those timers only have Timerwrap hooks.
Remove unnecessary condition from timeout & interval clearing.
@apapirovski apapirovski added timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. test Issues and PRs related to the tests. labels Feb 5, 2018
@nodejs-github-bot nodejs-github-bot added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Feb 5, 2018
@apapirovski apapirovski changed the title timers: timers: clean up, async integration for unref, simply clearTimeout Feb 5, 2018
@apapirovski apapirovski changed the title timers: clean up, async integration for unref, simply clearTimeout timers: clean up, async integration for unref, simplify clearTimeout Feb 5, 2018
@apapirovski
Copy link
Contributor Author

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. This does not surprise me, considering the my other PR in the same area.

Good work!

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 6, 2018
apapirovski added a commit that referenced this pull request Feb 8, 2018
A recent commit removed the usage of the second argument of
tryOnTimeout but left the definition in place. Remove it.

PR-URL: #18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
apapirovski added a commit that referenced this pull request Feb 8, 2018
It's possible for user-code to flip an existing timeout to
be an interval during its execution, in which case the
current code would crash due to start being undefined. Fix
this by providing a default start value within rearm.

PR-URL: #18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
apapirovski added a commit that referenced this pull request Feb 8, 2018
When async hooks integration for Timers was introduced, it was
not included in the code for unref'd or subsequently ref'd
timers which means those timers only have Timerwrap hooks.

PR-URL: #18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
apapirovski added a commit that referenced this pull request Feb 8, 2018
Remove unnecessary condition from timeout & interval clearing.

PR-URL: #18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@apapirovski
Copy link
Contributor Author

Landed in 1b05d7b, 568b6a5, c11cb03, and 8204b0f

@apapirovski apapirovski closed this Feb 8, 2018
@apapirovski apapirovski deleted the patch-timers-improvements branch February 8, 2018 14:02
@MylesBorins
Copy link
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
A recent commit removed the usage of the second argument of
tryOnTimeout but left the definition in place. Remove it.

PR-URL: nodejs#18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
It's possible for user-code to flip an existing timeout to
be an interval during its execution, in which case the
current code would crash due to start being undefined. Fix
this by providing a default start value within rearm.

PR-URL: nodejs#18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
When async hooks integration for Timers was introduced, it was
not included in the code for unref'd or subsequently ref'd
timers which means those timers only have Timerwrap hooks.

PR-URL: nodejs#18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Remove unnecessary condition from timeout & interval clearing.

PR-URL: nodejs#18579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Contributor

Should this be backported to v8.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

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. test Issues and PRs related to the tests. 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.

6 participants