[HTTP]Feat: pool for http headers path - #2486
Open
pulkit4tech wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2486 +/- ##
==========================================
- Coverage 85.23% 85.22% -0.01%
==========================================
Files 281 281
Lines 16773 16784 +11
==========================================
+ Hits 14296 14305 +9
- Misses 2015 2016 +1
- Partials 462 463 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rabbbit
reviewed
May 12, 2026
| urlTemplate, _ := url.Parse("http://my-service.prod.uber.internal:8080/v1") | ||
| b.ResetTimer() | ||
| b.ReportAllocs() | ||
| for i := 0; i < b.N; i++ { |
Contributor
There was a problem hiding this comment.
what about upgrading yarpc to a modern go? :)
Collaborator
Author
There was a problem hiding this comment.
sure, will do it as follow-up :) Thanks!
pulkit4tech
force-pushed
the
perf-http-header-pool
branch
from
May 12, 2026 13:12
783fcdf to
144d489
Compare
bananacocodrilo
approved these changes
May 13, 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.
Problem
Every outbound RPC call allocates a fresh
http.Headermap increateRequest→ToHTTPHeaders. This map is used only to buildand send request headers; after
roundTripreturns it is garbage.In high-throughput services this is a steady stream of short-lived
allocations that pressure the GC.
Solution
Add a package-level
sync.Poolof pre-sizedhttp.Headermaps(capacity 16 — enough for YARPC core headers + typical application
headers without growing the backing hash table). Each
call()borrowsa map from the pool, passes it through
createRequest→ToHTTPHeaders, then clears and returns it viadeferafterroundTripcompletes.net/httpserialises request headers to the wire insideroundTrip;no code path in
call()reads the request header map after thatreturns, so pool reuse is safe.
Changes
transport/http/outbound.goheaderPool(sync.Pool),_headerPoolInitSize = 16;call()borrows/returns map via defer;createRequestaccepts pre-allocatedhttp.Headertransport/http/outbound_test.gocreateRequestcall to pass header maptransport/http/createrequest_bench_test.gocreateRequestcalls to pass header mapBenchmarks
End-to-end,
-benchmem -benchtime=3s, AMD EPYC 7B13, Go 1.26.1:BenchmarkHeaderAlloc_EndToEnd_NoAppHeaders 141 → 139 allocs/op (-2) 14302 → 13894 B/op (-408 B)
BenchmarkHeaderAlloc_EndToEnd_10AppHeaders 201 → 195 allocs/op (-6) 21355 → 19052 B/op (-2303 B)
RELEASE NOTES: Pool http.Header maps on the outbound hot path, saving allocations and memory per RPC call