Skip to content

perf: cache common h2 header name buffers#5122

Open
mcollina wants to merge 1 commit intomainfrom
perf/h2-header-buffer-cache
Open

perf: cache common h2 header name buffers#5122
mcollina wants to merge 1 commit intomainfrom
perf/h2-header-buffer-cache

Conversation

@mcollina
Copy link
Copy Markdown
Member

Summary

Optimize the HTTP/2 response header path in client-h2 by:

  • avoiding the object rest/spread copy used to strip :status
  • skipping pseudo-headers inline during H2 header parsing
  • caching Buffer instances for a bounded set of common response header names

The header-name cache is intentionally bounded to avoid unbounded memory growth from attacker-controlled header names.

Validation

  • npx eslint lib/dispatcher/client-h2.js
  • npm run test:h2:core

Benchmark notes

I verified this with a controlled A/B .request() harness against main using the same simple H2 server and interleaved runs.

Average over 5 runs (80 rounds x 200 parallel requests):

  • this branch: 2401.39ms
  • main: 2452.65ms

That is roughly a 2.1% improvement on this request-heavy H2 workload.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@trivikr
Copy link
Copy Markdown
Member

trivikr commented Apr 26, 2026

There's an alternative PR which avoids response headers reserialization in #5085, which shows 5-7% improvement for similar tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants