Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.4k
lib: move duplicate spliceOne into internal/util#16221
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
starkwang commented Oct 15, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
vsemozhetbyt commented Oct 15, 2017
lib/url.js Outdated
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.
As this module already uses const, maybe we can use const here too?
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.
fixed
vsemozhetbyt commented Oct 15, 2017
Multiple early fails in the CI. Something is temporarily wrong? |
45c4a94 to f9d267bCompareBridgeAR commented Oct 15, 2017
@bmeurer are there plans to optimize splice sometime "soon"? |
starkwang commented Oct 15, 2017
And |
f9d267b to a4bd3acComparebmeurer commented Oct 15, 2017
We're working on As for |
lib/events.js Outdated
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.
It must have a lazy load here because (#15623):
It is because events.js is loaded before all the other modules in the dependency tree (because of bootstrapping process. Lazy loading errors prevents errors from being loaded before events is loaded.
starkwang commented Oct 15, 2017
@vsemozhetbyt Could you please restart a new CI? |
vsemozhetbyt commented Oct 15, 2017
lib/events.js Outdated
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.
Why not just use list.splice(position, 1) here?
This was introduced 3 years ago in d3f8db1
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.
According to #14082, it seems like Array#splice is still much slower than spliceOne.
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.
Than I'd rather have the simpler lazy loader, like #14167
varspliceOne; ... if(!spliceOne)spliceOne=require('internal/util').spliceOne;refack commented Oct 16, 2017
Run a microbenchmark: >console.time('native');for(leti=0;i<1e8;++i){global.x=[1,2,3,4];global.x.splice(2,1);};console.timeEnd('native') native: 31554.122ms>console.time('spliceOne');for(leti=0;i<1e8;++i){global.x=[1,2,3,4];spliceOne(global.x,2);};console.timeEnd('spliceOne') spliceOne: 3718.840msThat shows at ~10x better performance For |
a4bd3ac to f180a61Comparelib/events.js Outdated
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.
It would be better to write
if(spliceOne===undefined)spliceOne=require('internal/util').spliceOne;Otherwise there is a type conversion while evalutating if spliceOne is truthy.
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.
Same code in https://github.com/nodejs/node/blob/master/lib/events.js#L74
Should I rewrite them all?
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 keep it as is to reduce the churn.
apapirovskiOct 20, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Existing code is tricky but when adding new code and we're certain that something is either defined or undefined then a strict comparison is always better.
(Also, for example, domain can be null or undefined and maybe even other falsey values that we don't test for.)
lpinca commented Oct 20, 2017
@refack |
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code.
f180a61 to 380389aComparestarkwang commented Oct 20, 2017
Pushed commit to address comment |
refack commented Oct 20, 2017
refack commented Oct 20, 2017
Landed in 7a71cd7 🍾 |
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: #16221 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
refack commented Oct 20, 2017
P.S. we should write a benchmark that compares the two so we know when V8 catches up. |
MylesBorins commented Oct 23, 2017
This does not land cleanly on the 8.x Would someone be willing to manually backport? |
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: nodejs#16221 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: nodejs#16221 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
refack commented Oct 24, 2017
Backport PR: #16441 |
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: nodejs/node#16221 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: #16221 Backport-PR-URL: #16433 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: #16221 Backport-PR-URL: #16433 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
MylesBorins commented Nov 16, 2017
Should this be backported to |
lib/url.js and lib/events.js are using the same spliceOne function. This change is to move it into the internal/util for avoiding duplicate code. PR-URL: nodejs/node#16221 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
lib/url.js and lib/events.js are using the same spliceOne function.This change is to move it into the internal/util for avoiding duplicate code.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
url, events, util