-
Notifications
You must be signed in to change notification settings - Fork 5k
http: replace picohttpparser with a Rust parser; classify headers once and build fetch Response headers lazily #37132
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
Draft
dylan-conway
wants to merge
8
commits into
main
Choose a base branch
from
claude/picohttpparser-replacement-7287be
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.
Draft
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b47b76
Replace vendored picohttpparser with a Rust HTTP/1.1 response-head pa…
dylan-conway ee00fe6
verify-baseline: allowlist the runtime-dispatched IndexOfHttpCtl high…
dylan-conway 05ccec9
fetch: classify response header names once at parse time and build Fe…
dylan-conway fb86f21
http client: skip re-parsing an accumulating response head until the …
dylan-conway 996c7a4
Address review: keep Header::ZERO all-zero, assert HeaderName count, …
dylan-conway ef563fb
bench: require integer port and counts in response-headers.mjs
dylan-conway 58c2a53
http client: treat Content-Type as SSE only when the media type is ex…
dylan-conway 537b5ce
bench: use Number.isSafeInteger for response-headers.mjs counts
dylan-conway 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
| // Serves a 2-byte body under one of three response-header profiles, keyed by | ||
| // path: /small (2 headers), /nginx (14, API-gateway style), /cookies (long | ||
| // Location/Set-Cookie values). Pair with response-headers.mjs; run it in its | ||
| // own process (ideally pinned to other cores) so it doesn't share a CPU with | ||
| // the client: PORT=4001 bun bench/fetch/response-headers-server.mjs | ||
| const sets = { | ||
| small: { "Content-Type": "text/plain", "X-Id": "1" }, | ||
| nginx: { | ||
| "Server": "nginx/1.25.3", | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| "Vary": "Accept-Encoding", | ||
| "Cache-Control": "private, max-age=0, no-cache, no-store, must-revalidate", | ||
| "ETag": 'W/"bc55-7Zci8Yc4Bq3vJk8pQ0h5nX0m9sE"', | ||
| "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", | ||
| "X-Content-Type-Options": "nosniff", | ||
| "X-Frame-Options": "SAMEORIGIN", | ||
| "X-Request-Id": "3f1c9a7e-5b2d-4c8e-9f0a-1b2c3d4e5f60", | ||
| "Access-Control-Allow-Origin": "*", | ||
| "Access-Control-Expose-Headers": "X-Request-Id, ETag, Link", | ||
| "X-RateLimit-Limit": "5000", | ||
| "X-RateLimit-Remaining": "4987", | ||
| "X-RateLimit-Reset": "1723025489", | ||
| }, | ||
| cookies: { | ||
| "Location": | ||
| "https://accounts.example.com/signin/v2/identifier?continue=https%3A%2F%2Fmail.example.com%2Fmail%2F&service=mail&flowName=GlifWebSignIn&flowEntry=ServiceLogin", | ||
| "Set-Cookie": | ||
| "__Host-SESSION=CgQIARAB.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=2592000", | ||
| "Content-Type": "text/html; charset=UTF-8", | ||
| "Alt-Svc": 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', | ||
| }, | ||
| }; | ||
| const responses = Object.fromEntries(Object.entries(sets).map(([k, h]) => [k, { headers: new Headers(h) }])); | ||
| const server = Bun.serve({ | ||
| port: Number(process.env.PORT || 0), | ||
| reusePort: true, | ||
| fetch(req) { | ||
| const kind = req.url.slice(req.url.lastIndexOf("/") + 1) || "nginx"; | ||
| return new Response("ok", responses[kind]); | ||
| }, | ||
| }); | ||
| console.log(server.port); | ||
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,47 @@ | ||
| // Client CPU per fetch() against response-headers-server.mjs. | ||
| // bun bench/fetch/response-headers.mjs <port> [small|nginx|cookies] [body|get|iter] [requests] [concurrency] | ||
| // mode: body = read the body only; get = also headers.get(); iter = also iterate all headers. | ||
| // Reports requests/s and this process's CPU time per request (user+sys across | ||
| // all threads), which is the number to compare between builds when the server | ||
| // is the throughput bottleneck. | ||
| const [port, kind = "nginx", mode = "body", total = 200000, conc = 64] = process.argv.slice(2); | ||
| const url = `http://127.0.0.1:${port}/${kind}`; | ||
| const N = Number(total), | ||
| C = Number(conc); | ||
| let sink = 0; | ||
| async function one() { | ||
| const r = await fetch(url); | ||
| if (mode === "get") sink += r.headers.get("content-type").length; | ||
| else if (mode === "iter") for (const [k, v] of r.headers) sink += k.length + v.length; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const b = await r.arrayBuffer(); | ||
| sink += b.byteLength; | ||
| } | ||
| // warmup | ||
| await Promise.all(Array.from({ length: C }, one)); | ||
| const cpu0 = process.cpuUsage(); | ||
| const t0 = performance.now(); | ||
| let started = 0; | ||
| async function worker() { | ||
| while (started < N) { | ||
| started++; | ||
| await one(); | ||
| } | ||
| } | ||
| await Promise.all(Array.from({ length: C }, worker)); | ||
| const t = performance.now() - t0; | ||
| const cpu = process.cpuUsage(cpu0); | ||
| const cpuMs = (cpu.user + cpu.system) / 1000; | ||
| console.log( | ||
| JSON.stringify({ | ||
| kind, | ||
| mode, | ||
| N, | ||
| C, | ||
| ms: +t.toFixed(0), | ||
| rps: Math.round(N / (t / 1000)), | ||
| cpu_us_per_req: +((cpuMs * 1000) / N).toFixed(2), | ||
| user_ms: Math.round(cpu.user / 1000), | ||
| sys_ms: Math.round(cpu.system / 1000), | ||
| sink, | ||
| }), | ||
| ); | ||
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
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 was deleted.
Oops, something went wrong.
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.