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

http,https: avoid instanceof for WHATWG URL #12983

Merged
merged 1 commit into from
May 22, 2017

Conversation

mscdex
Copy link
Contributor

@mscdex mscdex commented May 11, 2017

Benchmark results:

                                                 improvement confidence      p.value
 http/create-clientrequest.js n=1000000 len=1        7.01 %        *** 1.281605e-08
 http/create-clientrequest.js n=1000000 len=128      4.02 %        *** 6.564820e-04
 http/create-clientrequest.js n=1000000 len=16       6.01 %        *** 8.660607e-07
 http/create-clientrequest.js n=1000000 len=32       5.68 %        *** 9.863084e-06
 http/create-clientrequest.js n=1000000 len=64       6.97 %        *** 9.791414e-10
 http/create-clientrequest.js n=1000000 len=8        7.65 %        *** 1.141693e-09

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

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

@mscdex mscdex added http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. performance Issues and PRs related to the performance of Node.js. labels May 11, 2017
@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. labels May 11, 2017
@@ -218,7 +218,8 @@ exports.request = function request(options, cb) {
if (!options.hostname) {
throw new Error('Unable to determine the domain name');
}
} else if (options instanceof url.URL) {
} else if (options && options[searchParamsSymbol] &&
options[searchParamsSymbol][searchParamsSymbol]) {
Copy link
Member

Choose a reason for hiding this comment

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

Would a require('internal/url').isURL() utility function be worthwhile to make this more convenient? Or would that kill any perf gain? I imagine wanting to use similar checks elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See here.

Copy link
Member

Choose a reason for hiding this comment

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

Ha! I thought the question sounded familiar as I was typing it ;-)

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

It's unfortunate we can't write an isURL without performance regression, but 🤷‍♂️

@@ -82,7 +82,8 @@ function ClientRequest(options, cb) {
if (!options.hostname) {
throw new Error('Unable to determine the domain name');
}
} else if (options instanceof url.URL) {
} else if (options && options[searchParamsSymbol] &&
options[searchParamsSymbol][searchParamsSymbol]) {
Copy link
Member

Choose a reason for hiding this comment

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

I am now wondering if this way of checking URLs is a bit hard to understand for someone who don't know the implementation details of URL...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not a whole lot that can be done about that. Using a helper function as previously noted incurs a measurable performance hit.

Copy link
Member

Choose a reason for hiding this comment

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

@mscdex Maybe a comment would help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mscdex mscdex force-pushed the http-client-avoid-instanceof-url branch 2 times, most recently from 43954e6 to 41ea7e9 Compare May 22, 2017 20:06
@mscdex
Copy link
Contributor Author

mscdex commented May 22, 2017

PR-URL: nodejs#12983
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
@mscdex mscdex force-pushed the http-client-avoid-instanceof-url branch from 41ea7e9 to ed36565 Compare May 22, 2017 22:07
@mscdex mscdex merged commit ed36565 into nodejs:master May 22, 2017
@mscdex mscdex deleted the http-client-avoid-instanceof-url branch May 22, 2017 22:09
jasnell pushed a commit that referenced this pull request May 23, 2017
PR-URL: #12983
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
jasnell pushed a commit that referenced this pull request May 23, 2017
PR-URL: #12983
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants