-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
vm: improve performance of vm.runIn*() #10816
Conversation
if (!Array.isArray(sigintListeners)) | ||
sigintListeners = sigintListeners ? [sigintListeners] : []; | ||
else | ||
if (!sigintListeners) |
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.
What about moving this to the conditional in the caller function (options && options.breakOnSigint
) to avoid creating the argsArray
and calling fn.apply()
?
Introduce benchmarks for vm.runInContext() and vm.runInThisContext().
Optimize for common cases in vm.runInContext() and vm.runInThisContext().
With the change suggested by @mscdex: $ node benchmark/compare.js --set 'n=10' --old './node-old' --new './node-new' vm > bench.csv
$ cat bench.csv | Rscript benchmark/compare.R bench
improvement confidence p.value
vm/run-in-context.js withSigintListener=0 breakOnSigint=0 n=10 1.69 % 0.4951121692
vm/run-in-context.js withSigintListener=0 breakOnSigint=1 n=10 7.41 % ** 0.0083586822
vm/run-in-context.js withSigintListener=1 breakOnSigint=0 n=10 6.29 % *** 0.0000524146
vm/run-in-context.js withSigintListener=1 breakOnSigint=1 n=10 1.23 % 0.4899217968
vm/run-in-this-context.js withSigintListener=0 breakOnSigint=0 n=10 -1.33 % 0.1885065483
vm/run-in-this-context.js withSigintListener=0 breakOnSigint=1 n=10 7.24 % * 0.0306398665
vm/run-in-this-context.js withSigintListener=1 breakOnSigint=0 n=10 -2.97 % 0.3052677075
vm/run-in-this-context.js withSigintListener=1 breakOnSigint=1 n=10 -0.01 % 0.9979790584
$ |
LGTM. FWIW here's the results I got when testing locally with a larger number of iterations:
|
@mscdex Is that with a large |
@Trott I left the |
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.
LGTM with some questions.
if (withSigintListener) | ||
process.on('SIGINT', () => {}); | ||
|
||
var i = 0; |
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.
Out of curiosity, is there a reason you define i
here and not in the for
block where it's used?
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 used crypto/get-ciphers.js
as a template and that is what is done there. I have no strong opinions on it so I left it outside the block.
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1], |
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.
Just a single iteration?
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.
Yeah, I had to bump up n
considerably to get the benchmarks to run long enough for me to be comfortable with the results, but then again I find myself having to do that a lot with many of the other existing benchmarks ...
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: #10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: #10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Landed in 030dd14 and ef1e77d |
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Optimize for common cases in vm.runInContext() and vm.runInThisContext(). PR-URL: nodejs#10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
lts??? |
ping re: LTS |
Since it's a perf-based refactor and not a behavior change, I think landing on 6.x is appropriate. |
This does not land cleanly in LTS. Would someone be able to backport? |
@MylesBorins This will land cleanly after #9388 lands on v6.x-staging. |
Removing the |
@Trott fwiw I doubt the naming anonymous functions is going to be backported for a couple releases |
Adding |
Optimize for common cases in
vm.runInContext()
andvm.runInThisContext()
whenbreakOnSigint
is set.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
vm benchmark