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

vm: improve performance of vm.runIn*() #10816

Closed
wants to merge 3 commits into from
Closed

Conversation

Trott
Copy link
Member

@Trott Trott commented Jan 15, 2017

Optimize for common cases in vm.runInContext() and vm.runInThisContext() when breakOnSigint is set.

$ 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.12 %            0.5268470825
 vm/run-in-context.js withSigintListener=0 breakOnSigint=1 n=10           6.90 %         ** 0.0039743927
 vm/run-in-context.js withSigintListener=1 breakOnSigint=0 n=10           5.19 %        *** 0.0001940968
 vm/run-in-context.js withSigintListener=1 breakOnSigint=1 n=10          -0.84 %            0.6936019893
 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=0 n=10      0.14 %            0.9651596335
 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=1 n=10      9.27 %         ** 0.0058309681
 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=0 n=10      1.13 %            0.5957890149
 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=1 n=10      2.21 %            0.2564659136
$ 
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)

vm benchmark

@Trott Trott added benchmark Issues and PRs related to the benchmark subsystem. vm Issues and PRs related to the vm subsystem. labels Jan 15, 2017
if (!Array.isArray(sigintListeners))
sigintListeners = sigintListeners ? [sigintListeners] : [];
else
if (!sigintListeners)
Copy link
Contributor

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().
@Trott
Copy link
Member Author

Trott commented Jan 15, 2017

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
$ 

@mscdex
Copy link
Contributor

mscdex commented Jan 15, 2017

LGTM.

FWIW here's the results I got when testing locally with a larger number of iterations:

                                                                         improvement confidence      p.value
 vm/run-in-context.js withSigintListener=0 breakOnSigint=0 n=700000           0.92 %            1.160369e-01
 vm/run-in-context.js withSigintListener=0 breakOnSigint=1 n=700000          12.29 %        *** 1.250555e-27
 vm/run-in-context.js withSigintListener=1 breakOnSigint=0 n=700000           2.14 %        *** 1.608620e-04
 vm/run-in-context.js withSigintListener=1 breakOnSigint=1 n=700000           2.22 %        *** 9.483438e-07
 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=0 n=700000      0.70 %            4.120226e-01
 vm/run-in-this-context.js withSigintListener=0 breakOnSigint=1 n=700000     12.15 %        *** 5.852368e-19
 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=0 n=700000     -0.22 %            7.966101e-01
 vm/run-in-this-context.js withSigintListener=1 breakOnSigint=1 n=700000      0.64 %            2.948688e-01

@Trott
Copy link
Member Author

Trott commented Jan 15, 2017

@mscdex Is that with a large n or by providing a large number for the --runs option or something else?

@mscdex
Copy link
Contributor

mscdex commented Jan 16, 2017

@Trott I left the --runs at the default (currently 30) and added --set n=700000 to the comparison command line.

Copy link
Member

@bnoordhuis bnoordhuis left a 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;
Copy link
Member

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?

Copy link
Member Author

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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a single iteration?

Copy link
Contributor

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 ...

@mscdex mscdex added the performance Issues and PRs related to the performance of Node.js. label Jan 17, 2017
@Trott
Copy link
Member Author

Trott commented Jan 17, 2017

jasnell pushed a commit that referenced this pull request Jan 18, 2017
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>
jasnell pushed a commit that referenced this pull request Jan 18, 2017
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>
@jasnell
Copy link
Member

jasnell commented Jan 18, 2017

Landed in 030dd14 and ef1e77d

@jasnell jasnell closed this Jan 18, 2017
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 18, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 27, 2017
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>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 27, 2017
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>
@italoacasas italoacasas mentioned this pull request Jan 29, 2017
@MylesBorins
Copy link
Contributor

lts???

@MylesBorins
Copy link
Contributor

ping re: LTS

@Trott
Copy link
Member Author

Trott commented May 8, 2017

Since it's a perf-based refactor and not a behavior change, I think landing on 6.x is appropriate.

@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Would someone be able to backport?

@Trott
Copy link
Member Author

Trott commented May 15, 2017

@MylesBorins This will land cleanly after #9388 lands on v6.x-staging.

@Trott
Copy link
Member Author

Trott commented May 15, 2017

Removing the backport-requested-v6.x label as I think landing that other PR first is probably the better way to go. Feel free to re-add the label if you disagree, of course.

@MylesBorins
Copy link
Contributor

@Trott fwiw I doubt the naming anonymous functions is going to be backported for a couple releases

@gibfahn gibfahn added the baking-for-lts PRs that need to wait before landing in a LTS release. label Jun 17, 2017
@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

Adding baking-for-lts, as this depends on #9388 which also has that label.

@MylesBorins MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
@Trott Trott deleted the optimize-vm branch January 13, 2022 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark Issues and PRs related to the benchmark subsystem. performance Issues and PRs related to the performance of Node.js. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants