-
Notifications
You must be signed in to change notification settings - Fork 5k
http: route identity chunked bodies through the multi-packet decode path #35411
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
robobun
wants to merge
5
commits into
main
Choose a base branch
from
farm/99436f9e/chunked-dispatch-gate-compressed
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.
+135
−1
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
850dfe9
http: route identity chunked bodies through the multi-packet decode path
robobun 4a504a9
[autofix.ci] apply automated fixes
autofix-ci[bot] 2181ace
test: trim stale -2 claim from small chunked body decode comment
robobun a18079a
test: move small chunked decode tests to fetch-gzip.test.ts
robobun 087ed6b
[autofix.ci] apply automated fixes
autofix-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Benchmark fetch() decoding small Transfer-Encoding: chunked bodies that | ||
| // arrive with their headers in a single read. Exercises the <=16 KiB | ||
| // dispatch in the HTTP client's chunked-body handler for both identity and | ||
| // gzip Content-Encoding. | ||
| import { bench, group, run } from "../runner.mjs"; | ||
| import net from "node:net"; | ||
| import zlib from "node:zlib"; | ||
|
|
||
| function chunked(buf) { | ||
| return Buffer.concat([ | ||
| Buffer.from(buf.length.toString(16) + "\r\n"), | ||
| buf, | ||
| Buffer.from("\r\n0\r\n\r\n"), | ||
| ]); | ||
| } | ||
|
|
||
| function makeReply(body, gzip) { | ||
| const payload = gzip ? zlib.gzipSync(body, { level: 6 }) : body; | ||
| return Buffer.concat([ | ||
| Buffer.from( | ||
| "HTTP/1.1 200 OK\r\n" + | ||
| "Transfer-Encoding: chunked\r\n" + | ||
| (gzip ? "Content-Encoding: gzip\r\n" : "") + | ||
| "Connection: keep-alive\r\n" + | ||
| "\r\n", | ||
| ), | ||
| chunked(payload), | ||
| ]); | ||
| } | ||
|
|
||
| const sizes = [256, 4096, 15 * 1024]; | ||
| const bodies = Object.fromEntries(sizes.map(n => [n, Buffer.alloc(n, "x")])); | ||
| const replies = {}; | ||
| for (const n of sizes) { | ||
| replies[`i${n}`] = makeReply(bodies[n], false); | ||
| replies[`g${n}`] = makeReply(bodies[n], true); | ||
| } | ||
|
|
||
| const server = net.createServer(sock => { | ||
| sock.setNoDelay(true); | ||
| let pending = Buffer.alloc(0); | ||
| sock.on("data", chunk => { | ||
| pending = Buffer.concat([pending, chunk]); | ||
| while (true) { | ||
| const end = pending.indexOf("\r\n\r\n"); | ||
| if (end < 0) break; | ||
| const head = pending.subarray(0, end).toString("latin1"); | ||
| pending = pending.subarray(end + 4); | ||
| const m = head.match(/^GET \/(\w+)/); | ||
| sock.write(replies[m[1]]); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| await new Promise(r => server.listen(0, r)); | ||
| const base = `http://127.0.0.1:${server.address().port}`; | ||
|
|
||
| // Warm the keep-alive connection so the first iteration doesn't pay connect. | ||
| for (const key of Object.keys(replies)) await fetch(`${base}/${key}`).then(r => r.arrayBuffer()); | ||
|
|
||
| for (const n of sizes) { | ||
| group(`chunked ${n}B`, () => { | ||
| bench("identity → arrayBuffer()", async () => { | ||
| const r = await fetch(`${base}/i${n}`); | ||
| await r.arrayBuffer(); | ||
| }); | ||
| bench("gzip → arrayBuffer()", async () => { | ||
| const r = await fetch(`${base}/g${n}`); | ||
| await r.arrayBuffer(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| await run(); | ||
| server.close(); | ||
| process.exit(0); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.