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: allow passing array of key/val into writeHead #35274

Closed
wants to merge 6 commits into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Sep 20, 2020

Enables an optimization when the user already has the headers
in an array form, e.g. when proxying.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@ronag ronag requested a review from mcollina September 20, 2020 07:33
@ronag ronag requested a review from a team as a code owner September 20, 2020 07:33
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Sep 20, 2020
Enables an optimization when the user already has the headers
in an array form, e.g. when proxying.
@addaleax
Copy link
Member

This needs docs changes, right?

@ronag
Copy link
Member Author

ronag commented Sep 20, 2020

@addaleax Added docs

@benjamingr
Copy link
Member

Enables an optimization when the user already has the headers in an array form, e.g. when proxying.

Why would proxying imply the user gets the headers in array form?

@ronag
Copy link
Member Author

ronag commented Sep 21, 2020

undici provides them in array form

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@ronag
Copy link
Member Author

ronag commented Sep 21, 2020

@benjamingr Here we would benefit from being able to pass the array directly without first converting it into an object.

@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Sep 21, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 21, 2020
@nodejs-github-bot
Copy link
Collaborator

@benjamingr
Copy link
Member

I still don't understand this feature request/PR. Is this is a specific format that afaik only unidici uses?

Wouldn't it make more sense to support raw headers as a string?

@ronag
Copy link
Member Author

ronag commented Sep 22, 2020

Is this is a specific format that afaik only unidici uses?

At the moment yes... since Node doesn't have this feature yet no one has optimized for it as far as I'm aware...

Wouldn't it make more sense to support raw headers as a string?

Sure... But since we already do arrays I don't see any advantage. I guess one does not exclude the other.

@benjamingr
Copy link
Member

Sure... But since we already do arrays I don't see any advantage. I guess one does not exclude the other.

I'm confused by this. This is an intermediary format that only one library uses. Passing a string of headers (concatenated) is something I've seen in many servers/languages.

Would the optimisation be impossible without going through the third (array) format?

@ronag
Copy link
Member Author

ronag commented Sep 22, 2020

I'm confused by this.

Due to the way our http parser works the most efficient way to get headers from node is through arrays (i.e. rawHeaders & rawTrailers). If we pass it as string it becomes inefficient to process the headers.

For best performance in core and user land should use flat arrays for headers. Strings don't allow efficient introspection and objects are expensive to create.

@mcollina maybe you are able to formulate this better?

@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 22, 2020
@lpinca
Copy link
Member

lpinca commented Sep 22, 2020

For best performance in core and user land should use flat arrays for headers. Strings don't allow efficient introspection and objects are expensive to create.

Do you have any benchmark for this? How much faster is creating an array instead of a plain object? Or is this related to how the HTTP parser works?

@ronag
Copy link
Member Author

ronag commented Sep 22, 2020

Do you have any benchmark for this? How much faster is creating an array instead of a plain object? Or is this related to how the HTTP parser works?

The parser outputs an Array.

@lpinca
Copy link
Member

lpinca commented Sep 22, 2020

Ok, but in this case the parser is not used no? Isn't OutgoingMessage writing directly to the socket?

Edit: Ah I get it now, it's for proxying. I guess the idea is to get the headers as received by the parser and directly forward them.

@ronag ronag requested a review from addaleax September 30, 2020 18:41
@ronag ronag added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 30, 2020
@ronag
Copy link
Member Author

ronag commented Sep 30, 2020

@benjamingr comment added

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 30, 2020
@nodejs-github-bot
Copy link
Collaborator

@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 9, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 9, 2020
@nodejs-github-bot
Copy link
Collaborator

@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 9, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 9, 2020
@nodejs-github-bot
Copy link
Collaborator

@ronag ronag added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 9, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 9, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2020

Commit Queue failed
- Loading data for nodejs/node/pull/35274
✔  Done loading data for nodejs/node/pull/35274
----------------------------------- PR info ------------------------------------
Title      http: allow passing array of key/val into writeHead (#35274)
Author     Robert Nagy  (@ronag)
Branch     ronag:write-head-array -> nodejs:master
Labels     author ready, http, semver-minor
Commits    6
 - http: allow passing array of key/val into writeHead
 - fixup: docs
 - fixup
 - fixup
 - fixup
 - fixup
Committers 1
 - Robert Nagy 
PR-URL: https://github.com/nodejs/node/pull/35274
Reviewed-By: Matteo Collina 
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Rich Trott 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/35274
Reviewed-By: Matteo Collina 
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Rich Trott 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - fixup
   ⚠  - fixup
   ✔  Last GitHub Actions successful
   ℹ  Last Full PR CI on 2020-10-09T12:42:51Z: https://ci.nodejs.org/job/node-test-pull-request/33490/
- Querying data for job/node-test-pull-request/33490/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
   ℹ  This PR was created on Sun, 20 Sep 2020 07:33:30 GMT
   ✔  Approvals: 3
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/35274#pullrequestreview-492926190
   ✔  - Benjamin Gruenbaum (@benjamingr): https://github.com/nodejs/node/pull/35274#pullrequestreview-494531574
   ✔  - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/35274#pullrequestreview-494545046
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
\nCommit Queue action: https://github.com/nodejs/node/actions/runs/298285943

@github-actions github-actions bot added the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Oct 9, 2020
@ronag
Copy link
Member Author

ronag commented Oct 10, 2020

Landed in d70c0ed

@ronag ronag closed this Oct 10, 2020
ronag added a commit that referenced this pull request Oct 10, 2020
Enables an optimization when the user already has the headers
in an array form, e.g. when proxying.

PR-URL: #35274
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins pushed a commit that referenced this pull request Oct 14, 2020
Enables an optimization when the user already has the headers
in an array form, e.g. when proxying.

PR-URL: #35274
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
MylesBorins added a commit that referenced this pull request Oct 14, 2020
Notable changes:

crypto:
  * update certdata to NSS 3.56 (Shelley Vohr) #35546
doc:
  * add aduh95 to collaborators (Antoine du Hamel) #35542
fs:
  * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494
http:
  * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274
src:
  * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512

PR-URL: TODO
@MylesBorins MylesBorins mentioned this pull request Oct 14, 2020
MylesBorins added a commit that referenced this pull request Oct 15, 2020
Notable changes:

crypto:
  * update certdata to NSS 3.56 (Shelley Vohr) #35546
doc:
  * add aduh95 to collaborators (Antoine du Hamel) #35542
fs:
  * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494
http:
  * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274
src:
  * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512

PR-URL: TODO
MylesBorins added a commit that referenced this pull request Oct 15, 2020
Notable changes:

crypto:
  * update certdata to NSS 3.56 (Shelley Vohr) #35546
doc:
  * add aduh95 to collaborators (Antoine du Hamel) #35542
fs:
  * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494
http:
  * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274
src:
  * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512

PR-URL: #35648
MylesBorins added a commit that referenced this pull request Oct 16, 2020
Notable changes:

crypto:
  * update certdata to NSS 3.56 (Shelley Vohr) #35546
doc:
  * add aduh95 to collaborators (Antoine du Hamel) #35542
fs:
  * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494
http:
  * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274
src:
  * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512

PR-URL: #35648
joesepi pushed a commit to joesepi/node that referenced this pull request Jan 8, 2021
Enables an optimization when the user already has the headers
in an array form, e.g. when proxying.

PR-URL: nodejs#35274
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@targos targos removed the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Sep 5, 2021
ryanhc pushed a commit to Samsung/lwnode that referenced this pull request Jun 29, 2022
Notable changes:

crypto:
  * update certdata to NSS 3.56 (Shelley Vohr) nodejs/node#35546
doc:
  * add aduh95 to collaborators (Antoine du Hamel) nodejs/node#35542
fs:
  * (SEMVER-MINOR) add rm method (Ian Sutherland) nodejs/node#35494
http:
  * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) nodejs/node#35274
src:
  * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) nodejs/node#35512

PR-URL: nodejs/node#35648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. http Issues or PRs related to the http subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants