-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: improve setImmediate() performance #4169
Conversation
CI is happy except for unrelated Windows test :) |
LGTM @Fishrock123 LGTY? :) |
@@ -409,6 +393,26 @@ function processImmediate() { | |||
} | |||
} | |||
|
|||
function tryOnImmediate(immediate, queue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, beat me to it I see. :P
I was going to leave this until after #4007, in part so that it would look similar.
I suggest we keep the naming consistent in some way with https://github.com/nodejs/node/pull/4007/files#diff-0a5d4868b2b9b17cf9e2c11f1bd1311eR177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using the try
prefix with the try-catch/finally
isolation PRs I've submitted in the past as that seems (to me) to make it more clear as to what the isolation functions are doing. shrug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the one in #4007 to _tryOnTimeout
, keeping the underspace from a prior incantation in internal timeouts. Mind adding it to this then?
LGTM so long as @Fishrock123 is happy |
@@ -0,0 +1,21 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot a 'use strict'
?
I'd rewrite the benchmarks so that the callbacks don't reference free variables (including |
@mscdex @Fishrock123 ... ping :-) |
'use strict'; | ||
|
||
var common = require('../common.js'); | ||
var bench = common.createBenchmark(main, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
?
d3ec30d
to
74adf50
Compare
@bnoordhuis I tried to rewrite the benchmarks according to your suggestions, but at least judging by the results of @jasnell Updated per your suggestions too. |
I'll try to look tomorrow |
@bnoordhuis @Fishrock123 ping |
@mscdex .. LGTM |
LGTM |
Will take a look when I get back home |
Marking this lts-watch but it would definitely need to sit for a while in master and v5 before pulling back |
@Fishrock123 Does this LGTY? |
immediate._onImmediate(); | ||
threw = false; | ||
} finally { | ||
if (threw === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
early return to avoid more indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you return early in a finally
block, the exception wouldn't be thrown, which would change behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow, how would that change?
The try - finally
will still catch the exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do something like
function foo() {
try {
throw new Error('foo');
} finally {
return;
}
}
the exception won't be thrown and execution will continue normally (as if you had done try { } catch (e) {}
, but without access to the exception object). If you remove the return
from the finally
block, execution will continue to the end of the finally
block at which point the exception will be thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I was under the impression we swallowed it for some reason, I guess this allows it to bubble up to the console?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume so. Only try {} catch(e) {}
or try {} finally { ... return; ... }
can swallow exceptions.
New CI with rebase onto |
I disagree. The implementation is effectively identical. This should land like any other patch fix. |
@@ -418,6 +404,27 @@ function processImmediate() { | |||
} | |||
|
|||
|
|||
function tryOnImmediate(immediate, queue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the deopt comment to here and clarify it a tad, ala https://github.com/nodejs/node/pull/4007/files#diff-0a5d4868b2b9b17cf9e2c11f1bd1311eR178 ? (I do need to add the v8 version to mine also..)
rename to match Brian’s setImmediate() refactor in nodejs#4169
bd485e9
to
75e02de
Compare
Made suggested changes. CI: https://ci.nodejs.org/job/node-test-pull-request/1953/ |
@Fishrock123 LGTY? |
@mscdex lgtm |
This commit improves setImmediate() performance by moving the try-finally block that wraps callback execution into a separate function because currently v8 never tries to optimize functions that contain try-finally blocks. With this change, there is a ~20-40% improvement in the included setImmediate() depth benchmarks. The breadth benchmarks show a slight improvement. PR-URL: nodejs#4169 Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
75e02de
to
089bef0
Compare
This commit improves setImmediate() performance by moving the try-finally block that wraps callback execution into a separate function because currently v8 never tries to optimize functions that contain try-finally blocks. With this change, there is a ~20-40% improvement in the included setImmediate() depth benchmarks. The breadth benchmarks show a slight improvement. PR-URL: #4169 Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) #5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) #5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) #4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) #5800 PR-URL: #5831
Notable changes: * buffer: Now properly throws RangeErrors on out-of-bounds writes (Matt Loring) nodejs#5605 - This effects write{Float|Double} when the noAssert option is not used. * timers: - Returned timeout objects now have a Timeout constructor name (Jeremiah Senkpiel) nodejs#5793 - Performance of Immediate processing is now ~20-40% faster (Brian White) nodejs#4169 * vm: Fixed a contextify regression introduced in v5.9.0 (Ali Ijaz Sheikh) nodejs#5800 PR-URL: nodejs#5831
Setting as don't land for the same reason as #4007 (comment) Keeping the timers changes in v6. Open to discussion |
This commit improves
setImmediate()
performance by moving thetry-finally
block that wraps callback execution into a separate function because currently v8 never tries to optimize functions that containtry-finally
blocks.With this change, there is a ~20-40% improvement in the included
setImmediate()
depth benchmarks. The breadth benchmarks show a slight improvement.