-
-
Notifications
You must be signed in to change notification settings - Fork 36k
http: cut per-message outgoing overhead #64346
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
Open
anonrig
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
anonrig:http-outgoing-overhead
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−33
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
|
|
||
| // The outgoing-header known-field matcher short-circuits on | ||
| // (length, first character) before lower-casing the name. Verify that | ||
| // known connection-relevant headers are still recognized in any casing, | ||
| // and that unknown headers sharing a known field's length and first | ||
| // letter are still sent through untouched. | ||
|
|
||
| const server = http.createServer(common.mustCall((req, res) => { | ||
| switch (req.url) { | ||
| case '/upper': | ||
| // Must be recognized: response uses identity framing, no chunking. | ||
| res.writeHead(200, { | ||
| 'CONTENT-LENGTH': '2', | ||
| 'CoNnEcTiOn': 'close', | ||
| }); | ||
| res.end('ok'); | ||
| break; | ||
| case '/nearmiss': | ||
| // Same length/first letter as known fields ('date', 'connection', | ||
| // 'content-length', 'transfer-encoding') but NOT known: they must | ||
| // be emitted verbatim and must not affect framing decisions. | ||
| res.writeHead(200, { | ||
| 'Dote': 'x', // Len 4, 'd' (like date) | ||
| 'Xonnection': 'y', // Len 10, wrong first char | ||
| 'Continues-Len': 'z', // Len 13, no known field | ||
| 'Content-Lengthy': 'w', // Len 15, no known field | ||
| 'Transfer-Encoders': 'v', // Len 17 minus... 18: unknown | ||
| }); | ||
| res.end('hi'); | ||
| break; | ||
| default: | ||
| res.writeHead(404); | ||
| res.end(); | ||
| } | ||
| }, 2)); | ||
|
|
||
| server.listen(0, common.mustCall(() => { | ||
| const port = server.address().port; | ||
|
|
||
| http.get({ port, path: '/upper' }, common.mustCall((res) => { | ||
| // Content-Length was recognized despite the casing: no chunking. | ||
| assert.strictEqual(res.headers['content-length'], '2'); | ||
| assert.strictEqual(res.headers['transfer-encoding'], undefined); | ||
| assert.strictEqual(res.headers.connection, 'close'); | ||
| res.resume(); | ||
| res.on('end', common.mustCall(() => { | ||
| http.get({ port, path: '/nearmiss' }, common.mustCall((res2) => { | ||
| assert.strictEqual(res2.headers.dote, 'x'); | ||
| assert.strictEqual(res2.headers.xonnection, 'y'); | ||
| assert.strictEqual(res2.headers['continues-len'], 'z'); | ||
| assert.strictEqual(res2.headers['content-lengthy'], 'w'); | ||
| assert.strictEqual(res2.headers['transfer-encoders'], 'v'); | ||
| // None of them are Content-Length/TE: chunked framing applies. | ||
| assert.strictEqual(res2.headers['transfer-encoding'], 'chunked'); | ||
| res2.resume(); | ||
| res2.on('end', common.mustCall(() => server.close())); | ||
| })); | ||
| })); | ||
| })); | ||
| })); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking but I doubt this is going to save much. There's also an inherent risk of false positives (e.g. that first clause also matches any other 4-letter string that starts with
d). My fear is that this is straining into unnecessary micro-optimization territory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On false positives: they're safe by design — a 4-letter
d-starting name that isn'tdatepasses the pre-filter and then falls through thetoLowerCase()+switch exactly as before; the filter only skips work for names that provably cannot match, it never misclassifies (test-http-outgoing-known-header-casing.js locks exactly this:Dote/Xonnectionetc. are emitted verbatim, odd-cased known fields still recognized).On whether it saves much: this line is what carries most of the PR's measured effect. Without it, the hoists alone were inside the noise (+0.9%, n.s.); with it, the mechanism benchmarks (fresh process per sample, 30 interleaved samples per binary, Welch t-test, re-confirmed against a clean rebuilt baseline on an idle machine) show flushHeaders with five headers +10.8% (p=1.5e-25) and a 24-custom-header response +6.0% (p=5.1e-12) — the per-header lowercase allocation dominates _storeHeader for responses with ordinary X-*/custom headers, which never match the switch. Happy to drop it if you feel the extra branching isn't worth it, but the data says it's the payload of this PR rather than the garnish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not worried about safety. Raw performance isn't the only goal. Keeping code easily readable, maintainable, etc is also important. Running a local artificial benchmark here, the impact is noticeable in isolation but shows zero statistically relevant impact in any of the http benchmarks.
I suspect caching the lenient header validation is likely a more meaningful change.
Not blocking, but I'm not convinced the additional complexity is actually worthwhile.