transport/http: make inbound header preallocation configurable - #2536
Merged
Conversation
Summary: Intent: - Preserve the default post-system-header sizing from PR #2521 while giving header-heavy services an escape hatch for requests dominated by unrelated HTTP headers. - Let downstream services choose the CPU and memory tradeoff that matches their inbound header mix. Changes: - Added remaining, scan, and disabled inbound header preallocation strategies through the Go API and HTTP transport configuration. - Made the opt-in scan count unique application, tracing, proxy, and grabbed headers, including collision and minimum-threshold handling. - Precomputed grabbed-header lookup keys per inbound so scanning adds no per-request allocations, with focused tests and benchmarks for each strategy. Jira Issues: T3-RPC-11408 --- <sub>Generated by the 🪄 [pr-create](https://sg.uberinternal.com/code.uber.internal/uber-code/devexp-agent-marketplace/-/blob/claude-code/plugins/dev/uber-dev/skills/pr-create/SKILL.md) skill in devexp-agent-marketplace</sub>
bananacocodrilo
marked this pull request as ready for review
August 19, 2026 11:20
bananacocodrilo
commented
Aug 24, 2026
maryis
reviewed
Aug 26, 2026
| grabHeaders []headerPreallocationGrabHeader, | ||
| ) int { | ||
| switch strategy { | ||
| case "", HeaderPreallocationUnfiltered: |
Collaborator
Author
There was a problem hiding this comment.
I'm removing it and making it so "no config" gets set to unfiltered to make it more clear
maryis
reviewed
Aug 26, 2026
| grabHeaders []headerPreallocationGrabHeader, | ||
| ) int { | ||
| switch strategy { | ||
| case "", HeaderPreallocationUnfiltered: |
| } | ||
| } | ||
|
|
||
| // Raw and prefixed forms can produce the same canonical transport key. |
There was a problem hiding this comment.
should we move this comment to line 108?
| if len(values) > 0 { | ||
| return values[0] | ||
| } | ||
| return "" |
There was a problem hiding this comment.
Is there possibility that value for canonicalKey is empty, but not for lowerKey? In this case we bypass the lowerKey one
Collaborator
Author
There was a problem hiding this comment.
There was!
| ttl := popHeader(req.Header, TTLMSHeader) | ||
|
|
||
| transportHeader := transport.NewHeadersWithCapacity(len(req.Header)) | ||
| transportHeader := transport.NewHeadersWithCapacity(inboundHeaderCapacity( |
There was a problem hiding this comment.
inboundHeaderCapacity returns 0 for Disabled option, and we end up having an empty map without item or originalItem keys.
Collaborator
Author
There was a problem hiding this comment.
transport.Headers.With lazily allocates both maps when the first header is added. No headers ends with no allocations.
bananacocodrilo
force-pushed
the
wt/header-preallocation-strategy
branch
from
August 26, 2026 13:59
24b179c to
f096634
Compare
maryis
approved these changes
Aug 26, 2026
pulkit4tech
approved these changes
Aug 26, 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.
Description
Intent:
Changes:
unfiltered,scan, anddisabledinbound header preallocation strategies through the Go API and HTTP transport configuration.HeaderPreallocationStrategyenum while preserving omitted-versus-explicit configuration semantics.unfilteredthe default; it uses the unfiltered number of request headers remaining after YARPC system headers are removed.Test Plan
go test ./transport/httpaifx verifygo test ./transport/http -run '^$' -bench '^BenchmarkFromHTTPHeadersCapacity' -benchmem -benchtime=200ms -count=3Revert Plan
Revert this PR to restore PR #2521's unconditional post-system-header request-header-count preallocation.
Issues
T3-RPC-11408
RELEASE NOTES:
Added configurable inbound HTTP header preallocation strategies.