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

url: performance improvement in URL implementation #10469

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Dec 27, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

url

Description of change

Yields about a 25% average performance improvement

@nodejs-github-bot nodejs-github-bot added the url Issues and PRs related to the legacy built-in url module. label Dec 27, 2016
@mscdex
Copy link
Contributor

mscdex commented Dec 27, 2016

It looks like the file mode was changed accidentally.

@mscdex
Copy link
Contributor

mscdex commented Dec 27, 2016

I've added dont-land-on-* labels because of the use of bind() which is only faster in node v7.

@jasnell
Copy link
Member Author

jasnell commented Dec 27, 2016

grr.. ok, file mode should be fixed now.

host, port, path, query, fragment) {
if (flags & binding.URL_FLAGS_FAILED)
return;
const newIsSpecial = (flags & binding.URL_FLAGS_SPECIAL) != 0;
Copy link
Member

Choose a reason for hiding this comment

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

!==?

Copy link
Member

Choose a reason for hiding this comment

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

While you're at it, maybe != -> !== on lines 222 and 226 below?

const s = this[special];
const ctx = this[context];
if ((s && !newIsSpecial) ||
(!s && newIsSpecial) ||
Copy link
Contributor

@thefourtheye thefourtheye Dec 27, 2016

Choose a reason for hiding this comment

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

Would !!s !== !!newIsSpecial be better?

Copy link

Choose a reason for hiding this comment

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

how about !s !== !newIsSpecial?

Copy link
Member Author

Choose a reason for hiding this comment

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

this[special] is guaranteed to be a boolean. s and !s are sufficient. There's no need (and no benefit) for getting fancy with it.

@jasnell
Copy link
Member Author

jasnell commented Dec 27, 2016

Updated to address nits

if ((s && !newIsSpecial) ||
(!s && newIsSpecial) ||
(newIsSpecial && !s &&
ctx.host === undefined)) {
Copy link

Choose a reason for hiding this comment

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

3rd one will never trigger?

Copy link
Member Author

Choose a reason for hiding this comment

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

ha! good catch... fixed!

host, port, path, query, fragment) {
if (flags & binding.URL_FLAGS_FAILED)
throw new TypeError('Invalid URL');
const ctx = this[context];
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that we have to do this. Isn't it like caching the length of an array before a for loop (which V8 is able to optimize)?

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 wouldn't say that we have to do this. This is more a code hygiene thing for me to avoid duplicated accessor calls but beyond that the impact is negligible.

@jasnell
Copy link
Member Author

jasnell commented Dec 29, 2016

This PR will need to be updated after #10408 lands. Marking as blocked until that does.

@jasnell jasnell added the blocked PRs that are blocked by other issues or PRs. label Dec 29, 2016
Yields about a 25% average performance improvement
@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2016

Updated.. unblocking

@jasnell jasnell removed blocked PRs that are blocked by other issues or PRs. dont-land-on-v7.x labels Dec 30, 2016
@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2016

@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2016

Failures in freebsd are unrelated

jasnell added a commit that referenced this pull request Dec 30, 2016
Yields about a 25% average performance improvement

PR-URL: #10469
Reviewed-By: Michaël Zasso <[email protected]>
@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2016

Landed in 2213f36

@jasnell jasnell closed this Dec 30, 2016
@mscdex
Copy link
Contributor

mscdex commented Dec 30, 2016

FWIW I just noticed the file mode changed again in the landed commit.

@jasnell
Copy link
Member Author

jasnell commented Dec 30, 2016 via email

evanlucas pushed a commit that referenced this pull request Jan 3, 2017
Yields about a 25% average performance improvement

PR-URL: #10469
Reviewed-By: Michaël Zasso <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
Yields about a 25% average performance improvement

PR-URL: #10469
Reviewed-By: Michaël Zasso <[email protected]>
@joyeecheung joyeecheung added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
url Issues and PRs related to the legacy built-in url module. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants