Uh oh!
There was an error while loading. Please reload this page.
timers: do not use user object call/apply - #12960
Conversation
Trott
commented
May 11, 2017
Will have to run a benchmark to see performance impact... |
|
Trott
commented
May 11, 2017
Working on it... |
Trott
commented
May 11, 2017
FWIW it used to be common with this sort of code to put at the top of the file: varapply=(function(){}).apply;And then use that (as it has no dependencies on even someone overriding the global |
There was a problem hiding this comment.
Missed the .apply case.
Make sure to add a test with >3 arguments.
5ab342a to
aeb5af9CompareTimers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. Refs: nodejs#12956
daurnimator
commented
May 11, 2017
Looks good now :) |
Trott
commented
May 11, 2017
Had to alter the implementation a bit from the initial attempt to get the benchmark to be neutral. Current implementation in this PR compares like this against master: improvement confidence p.value timers/immediate.js type="breadth" thousands=2000 -0.43 % 0.67056272 timers/immediate.js type="breadth1" thousands=2000 0.10 % 0.92761906 timers/immediate.js type="breadth4" thousands=2000 -1.59 % 0.19085909 timers/immediate.js type="clear" thousands=2000 0.11 % 0.89212673 timers/immediate.js type="depth" thousands=2000 -1.63 % 0.07178678 timers/immediate.js type="depth1" thousands=2000 0.90 % 0.35150859 timers/set-immediate-breadth-args.js millions=5 0.49 % 0.50576472 timers/set-immediate-breadth.js millions=10 -0.34 % 0.36237802 timers/set-immediate-depth-args.js millions=10 -1.44 % 0.10138701 timers/set-immediate-depth.js millions=10 -0.81 % 0.42620317 timers/timers-breadth.js thousands=500 -0.18 % 0.80576168 timers/timers-cancel-pooled.js thousands=500 1.10 % 0.27800863 timers/timers-cancel-unpooled.js thousands=100 0.31 % 0.22503088 timers/timers-depth.js thousands=1 0.02 % 0.95753131 timers/timers-insert-pooled.js thousands=500 -0.21 % 0.85337983 timers/timers-insert-unpooled.js thousands=100 0.06 % 0.93189629 timers/timers-timeout-pooled.js thousands=500 -0.77 % 0.48345237 |
Trott
commented
May 11, 2017
TimothyGu
commented
May 11, 2017
Well, for perfect robustness (and Web IDL compliance, which I know we don't particularly care for) we need to get the initial value of |
refack
commented
May 11, 2017
I think we should leak C++ helpers for |
TimothyGu
commented
May 11, 2017
They are equivalent, and the C++ helpers will be much slower than JS. |
Fishrock123
left a comment
There was a problem hiding this comment.
LGTM pending some benchmark / profiling output, which is the reason this code was this way.
Benchmark results are included above. They show no significant performance change. No changes have been applied to this PR since those benchmarks have been run. |
refack
commented
May 11, 2017
How about hiding the defaults behind symbols on |
mscdex
commented
May 11, 2017
The benchmark results look ok to me, but I am also concerned about this being a slippery slope. Just how far down the rabbit hole of protecting against userland do we have to go? |
I'd like us to go this far down the rabbit hole:
If the answer to both questions is "yes" (or at least "seems likely"), then I'm good with it. On the "affect actual users", I should note that I may be making an incorrect assumption here. I assumed that because @daurnimator opened an issue about this behavior, it is something that affected them. |
refack
commented
May 11, 2017
@TimothyGu I followed up on your suggestion #12981 |
jasnell
commented
May 11, 2017
Just noting... I've been stewing over an internal module that captures the original exports for key items like |
daurnimator
commented
May 12, 2017
Indeed. And this was just the first thing I ran into, as |
Timers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. PR-URL: nodejs#12960 Ref: nodejs#12956 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Trott
commented
May 13, 2017
Landed in 98609fc. |
Timers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. PR-URL: nodejs#12960 Ref: nodejs#12956 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins
commented
Jun 22, 2017
is this applicable to lts v6.x? |
Trott
commented
Jun 23, 2017
@MylesBorins Yes. |
MylesBorins
commented
Jul 17, 2017
Failures on v6.x Can you please backport |
Trott
commented
Jul 17, 2017
@MylesBorins Needs #12027 to land first, then that error should go away. |
Trott
commented
Jul 17, 2017
(Removing |
Timers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. PR-URL: #12960 Ref: #12956 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins
commented
Aug 14, 2017
Timers should work even if the user has monkey-patched `.call()` and `.apply()` to undesirable values. PR-URL: #12960 Ref: #12956 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
setTimeout()andsetInterval()should work even if the user hasmonkey-patched
.call()and.apply()to undesirable values. (This istrue for
setImmediate()as well, butsetImmediate()works just finein the current implementation. The test added here nonetheless adds a
test for
setImmediate()as well assetTimeout()andsetInterval().Refs: #12956
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
timers