-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
util: improve spliceOne perf #20453
Conversation
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 %
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 the comment addressed.
lib/internal/util.js
Outdated
@@ -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() |
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.
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
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.
Addressed
benchmark/util/splice-one.js
Outdated
}, { flags: ['--expose-internals'] }); | ||
|
||
function main({ n, size, type }) { | ||
const { spliceOne } = require('internal/util'); |
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 curious, why put this here?
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.
The benchmark runs with --expose-internals
so the main function has access to them but the outside doesn't.
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. |
Made all the requested changes. |
What do the benchmark results look like for the newly added cases? |
@mscdex Didn't have time for 100 runs but here's 30:
|
Landed in b04d092 |
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>
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>
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>
Do less variable allocations and reassignments inside
spliceOne
since it's relied on by some performance sensitive code. This also adds a benchmark forspliceOne
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes