FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

lib: move duplicate spliceOne into internal/util by starkwang · Pull Request #16221 · nodejs/node · GitHub

/ node Public

lib: move duplicate spliceOne into internal/util - #16221

Closed
starkwang wants to merge 1 commit into
nodejs:masterfrom
starkwang:move-splice-one
Closed

lib: move duplicate spliceOne into internal/util#16221
starkwang wants to merge 1 commit into
nodejs:masterfrom
starkwang:move-splice-one

Conversation

starkwang commented Oct 15, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

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), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

url, events, util

nodejs-github-bot added events Issues and PRs related to the events subsystem / EventEmitter. url Issues and PRs related to the legacy built-in url module. util Issues and PRs related to the built-in util module. labels Oct 15, 2017

Copy link
Copy Markdown
Contributor

Comment thread lib/url.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As this module already uses const, maybe we can use const here too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed

Copy link
Copy Markdown
Contributor

Multiple early fails in the CI. Something is temporarily wrong?

Copy link
Copy Markdown
Member

@bmeurer are there plans to optimize splice sometime "soon"?

Copy link
Copy Markdown
Contributor Author

@bmeurer are there plans to optimize splice sometime "soon"?

And Array.join: https://github.com/nodejs/node/blob/master/lib/internal/util.js#L261

bmeurer commented Oct 15, 2017

Copy link
Copy Markdown
Member

We're working on Array#slice, but mostly on the clone case, which should also be usable for Array#splice. Which case is most interesting for Array#splice?

As for Array#join (and Array#toString): One day... hopefully not too far away...

Comment thread lib/events.js Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt Could you please restart a new CI?

Copy link
Copy Markdown
Contributor

Comment thread lib/events.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why not just use list.splice(position, 1) here?
This was introduced 3 years ago in d3f8db1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

According to #14082, it seems like Array#splice is still much slower than spliceOne.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Than I'd rather have the simpler lazy loader, like #14167

var spliceOne;
...
if (!spliceOne) spliceOne = require('internal/util').spliceOne;

refack commented Oct 16, 2017

Copy link
Copy Markdown
Contributor

Run a microbenchmark:

> console.time('native'); for (let i = 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 (let i = 0; i < 1e8; ++i) { global.x = [1,2,3,4]; spliceOne(global.x, 2); };console.timeEnd('spliceOne')
spliceOne: 3718.840ms

That shows at ~10x better performance

For url I get it, but IMHO removeListener is not a hot path and is not worth the lazy load mechanics.

Comment thread lib/events.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Same code in https://github.com/nodejs/node/blob/master/lib/events.js#L74
Should I rewrite them all?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would keep it as is to reduce the churn.

apapirovski Oct 20, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

@refack EventEmitter#removeListener() is used extensively in _http_server.js so I'd say it's equally important.

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.

Copy link
Copy Markdown
Contributor Author

Pushed commit to address comment

refack self-assigned this Oct 20, 2017

refack commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

refack commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

Landed in 7a71cd7

🍾

refack closed this Oct 20, 2017
refack pushed a commit that referenced this pull request Oct 20, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>

refack commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

P.S. we should write a benchmark that compares the two so we know when V8 catches up.

Copy link
Copy Markdown
Contributor

This does not land cleanly on the 8.x

Would someone be willing to manually backport?

lpinca pushed a commit to lpinca/node that referenced this pull request Oct 24, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
refack pushed a commit to refack/node that referenced this pull request Oct 24, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>

refack commented Oct 24, 2017

Copy link
Copy Markdown
Contributor

Backport PR: #16441

addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
gibfahn pushed a commit that referenced this pull request Oct 30, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
gibfahn pushed a commit that referenced this pull request Oct 31, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
gibfahn mentioned this pull request Oct 31, 2017

Copy link
Copy Markdown
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
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 <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
refack removed their assignment Oct 12, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

events Issues and PRs related to the events subsystem / EventEmitter. url Issues and PRs related to the legacy built-in url module. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL