perf: optimize http/2 request hot path#5483
Merged
Merged
Conversation
Fast-path in-order completions in completeRequest, avoid once wrappers and dead-stream listener removal, use a single pre-shaped stream state object, cache the session ref state, and memoize getProtocolFromUrlString. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Matteo Collina <hello@matteocollina.com>
95e5ca3 to
86faa6a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5483 +/- ##
==========================================
- Coverage 93.45% 93.43% -0.03%
==========================================
Files 110 110
Lines 37147 37247 +100
==========================================
+ Hits 34717 34800 +83
- Misses 2430 2447 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
metcoder95
approved these changes
Jul 2, 2026
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.
Profiled the H2 client and removed the main client-side hot spots:
completeRequest: fast-path in-order completions by advancingkRunningIdx(like H1) instead of an O(n)indexOf+splice; out-of-order completions keep the splice pathoninstead ofoncefor self-removing stream handlers, and skip listener removal on already-closed streams (handlers null-guard on the stream state)finalizeRequest/openStreamhoisted out of per-request closuresref()/unref()calls (session ref proxies to the socket)getProtocolFromUrlStringBenchmarks (single connection, local H2 server, interleaved A/B vs main): +5-6% req/s at 100 parallel requests, +27% at 1000, +51% at 2000; +15% with a 10-connection Pool. Remaining cost is dominated by node core
session.request()internals.🤖 Generated with Claude Code