perf: lazily materialize raw h2 headers#5123
Open
mcollina wants to merge 1 commit intoperf/h2-header-buffer-cachefrom
Open
perf: lazily materialize raw h2 headers#5123mcollina wants to merge 1 commit intoperf/h2-header-buffer-cachefrom
mcollina wants to merge 1 commit intoperf/h2-header-buffer-cachefrom
Conversation
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## perf/h2-header-buffer-cache #5123 +/- ##
==============================================================
Coverage ? 93.11%
==============================================================
Files ? 110
Lines ? 35992
Branches ? 0
==============================================================
Hits ? 33514
Misses ? 2478
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
There's an alternative PR which avoids response headers reserialization in #5085, which shows 5-7% improvement for similar tests. |
metcoder95
approved these changes
Apr 30, 2026
Member
|
Agree with the optimization of #5085 but I also consider that this improvement is worth it, as keeping the raw headers on the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This stacks on top of #5122.
It keeps the bounded common-header buffer cache, and adds a follow-up optimization for the HTTP/2 response path:
controller.rawHeadersis actually accessedcontroller.rawHeaderswhenresponseHeaders === 'raw'The goal is to avoid paying the
parseH2Headers()allocation cost on the hot path when callers only need the normal parsed header object.Validation
npx eslint lib/core/request.js lib/dispatcher/client-h2.js lib/api/api-request.js lib/api/api-stream.js lib/api/api-connect.js lib/api/api-upgrade.js lib/api/api-pipeline.jsnpm run test:h2:corenpm run test:h2:fetchBenchmark notes
I verified this against commit
63a1b0fffrom #5122 using the same controlled H2.request()harness and interleaved runs.Average over 5 runs (
80 rounds x 200 parallel requests):63a1b0ff:2409.08ms2396.64msThat is roughly a 0.5% improvement on top of the previous optimization.