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: improve ClientRequest constructor #10654

Merged
merged 6 commits into from
Jan 13, 2017

Conversation

mscdex
Copy link
Contributor

@mscdex mscdex commented Jan 6, 2017

These PRs improve ClientRequest creation performance and tidy up a few other things.

Results with the included benchmark:

                                                    improvement significant      p.value
 http/create-clientrequest.js n=1000000 pathlen=1       19.66 %         *** 5.177002e-26
 http/create-clientrequest.js n=1000000 pathlen=128      6.25 %         *** 2.631094e-07
 http/create-clientrequest.js n=1000000 pathlen=16      17.25 %         *** 1.114277e-27
 http/create-clientrequest.js n=1000000 pathlen=32      15.81 %         *** 1.993393e-24
 http/create-clientrequest.js n=1000000 pathlen=64       6.67 %         *** 1.037841e-11
 http/create-clientrequest.js n=1000000 pathlen=8       16.12 %         *** 4.243041e-23

/cc @nodejs/http

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

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)
  • http

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label Jan 6, 2017
@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. dont-land-on-v7.x labels Jan 6, 2017
if (!common._checkIsHttpToken(method)) {
throw new TypeError('Method must be a valid HTTP token');

if (methodIsString) {
Copy link
Member

Choose a reason for hiding this comment

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

What if method is the empty string? It defaulted to 'GET' before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed + test added.

@mscdex
Copy link
Contributor Author

mscdex commented Jan 6, 2017

CI after another fix: https://ci.nodejs.org/job/node-test-pull-request/5720/

// checks can greatly outperform the equivalent regexp (tested in V8 5.4).
function isInvalidPath(s) {
var len = s.length;
if (len--) { if (s.charCodeAt(0) <= 32) return true; } else return false;
Copy link
Member

Choose a reason for hiding this comment

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

I think assumption that path length is usually less than 6 chars is very far fetched. Should we really specialize to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just loop unrolling and from my testing it seems to help, no matter what the length is.

Copy link
Member

Choose a reason for hiding this comment

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

Is the path not always expected to begin with /? If so, the check for s.charCodeAt(0) can look specifically for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasnell The path does not always have to begin with a forward slash. Some notable examples include the HTTP CONNECT and OPTIONS methods which may use an absolute URI or asterisk respectively.

Copy link
Member

Choose a reason for hiding this comment

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

ah yes... good ole CONNECT and OPTIONS...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@indutny Did that answer your question? If so, does this PR LGTY?

@mscdex
Copy link
Contributor Author

mscdex commented Jan 7, 2017

I've changed the path validation function implementation a bit to squeeze out a tiny bit more performance. CI again: https://ci.nodejs.org/job/node-test-pull-request/5744/ https://ci.nodejs.org/job/node-test-pull-request/5745/

@jasnell
Copy link
Member

jasnell commented Jan 10, 2017

@indutny ... does this LGTY with the recent updates?

Copy link
Member

@indutny indutny left a comment

Choose a reason for hiding this comment

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

LGTM

@mscdex
Copy link
Contributor Author

mscdex commented Jan 13, 2017

CI once more before landing: https://ci.nodejs.org/job/node-test-pull-request/5853/

PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@mscdex mscdex mentioned this pull request Jan 19, 2017
3 tasks
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 23, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this pull request Jan 25, 2017
PR-URL: nodejs#10654
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@italoacasas italoacasas mentioned this pull request Jan 29, 2017
@MylesBorins
Copy link
Contributor

should this be backported?

@MylesBorins
Copy link
Contributor

ping

@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

should this be backported?

ping @mscdex

@MylesBorins
Copy link
Contributor

ping

@MylesBorins MylesBorins added the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 14, 2017
@MylesBorins
Copy link
Contributor

setting as baking for now

@MylesBorins MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants