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

util: improve spliceOne perf #20453

Closed
wants to merge 3 commits into from

Conversation

apapirovski
Copy link
Member

Do less variable allocations and reassignments inside spliceOne since it's relied on by some performance sensitive code. This also adds a benchmark for spliceOne.

                                   confidence improvement accuracy (*)   (**)  (***)
util/splice.js size=10 n=10000000          **      2.95 %       ±1.83% ±2.46% ±3.26%
util/splice.js size=100 n=10000000        ***     10.68 %       ±1.46% ±1.98% ±2.66%
util/splice.js size=500 n=10000000        ***     11.26 %       ±1.23% ±1.65% ±2.19%
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Do less variable allocations and reassignments inside spliceOne
since it's relied on by some performance sensitive code.

                                   confidence improvement
util/splice.js size=10 n=10000000          **      2.95 %
util/splice.js size=100 n=10000000        ***     10.68 %
util/splice.js size=500 n=10000000        ***     11.26 %
@apapirovski apapirovski added the util Issues and PRs related to the built-in util module. label May 1, 2018
@apapirovski
Copy link
Member Author

Copy link
Member

@BridgeAR BridgeAR 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 the comment addressed.

@@ -322,10 +322,11 @@ function join(output, separator) {
return str;
}

// About 1.5x faster than the two-arg version of Array#splice().
// Depending on the size of the array, this is anywhere between 1.5-10x
// faster than the two-arg version of Array#splice()
Copy link
Member

Choose a reason for hiding this comment

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

Please add the V8 version this is tested with. And there is a new faster version that is currently deactivated. See https://bugs.chromium.org/p/v8/issues/detail?id=7221

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed

}, { flags: ['--expose-internals'] });

function main({ n, size, type }) {
const { spliceOne } = require('internal/util');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious, why put this here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The benchmark runs with --expose-internals so the main function has access to them but the outside doesn't.

@mscdex
Copy link
Contributor

mscdex commented May 1, 2018

It might be a good idea to also add other special cases for the benchmark, such as splicing the first element and the last element.

@apapirovski
Copy link
Member Author

Made all the requested changes.

CI: https://ci.nodejs.org/job/node-test-pull-request/14613/

@mscdex
Copy link
Contributor

mscdex commented May 1, 2018

What do the benchmark results look like for the newly added cases?

@apapirovski
Copy link
Member Author

@mscdex Didn't have time for 100 runs but here's 30:

 util/splice-one.js size=10 pos='end' n=10000000              *      1.36 %       ±1.25% ±1.66% ±2.17%
 util/splice-one.js size=10 pos='middle' n=10000000         ***      4.31 %       ±1.90% ±2.53% ±3.29%
 util/splice-one.js size=10 pos='start' n=10000000          ***      7.90 %       ±1.38% ±1.84% ±2.40%
 util/splice-one.js size=100 pos='end' n=10000000                   -0.33 %       ±1.78% ±2.37% ±3.09%
 util/splice-one.js size=100 pos='middle' n=10000000        ***     12.21 %       ±1.07% ±1.43% ±1.86%
 util/splice-one.js size=100 pos='start' n=10000000         ***      9.94 %       ±1.12% ±1.49% ±1.95%
 util/splice-one.js size=500 pos='end' n=10000000             *      1.60 %       ±1.34% ±1.78% ±2.33%
 util/splice-one.js size=500 pos='middle' n=10000000        ***     11.28 %       ±1.04% ±1.38% ±1.80%
 util/splice-one.js size=500 pos='start' n=10000000         ***     12.45 %       ±0.84% ±1.12% ±1.46%

@apapirovski apapirovski added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 2, 2018
@apapirovski
Copy link
Member Author

Landed in b04d092

@apapirovski apapirovski closed this May 3, 2018
@apapirovski apapirovski deleted the patch-splice-one-perf branch May 3, 2018 12:47
apapirovski added a commit that referenced this pull request May 3, 2018
Do less variable allocations and reassignments inside spliceOne
since it's relied on by some performance sensitive code.

PR-URL: #20453
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 4, 2018
Do less variable allocations and reassignments inside spliceOne
since it's relied on by some performance sensitive code.

PR-URL: #20453
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@MylesBorins MylesBorins mentioned this pull request May 8, 2018
MylesBorins pushed a commit that referenced this pull request May 8, 2018
Do less variable allocations and reassignments inside spliceOne
since it's relied on by some performance sensitive code.

PR-URL: #20453
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
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. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants