Repository navigation
perf: fuse uncommon header name conversion - #2795
Merged
Merged
Conversation
dunglas
requested changes
Oct 31, 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.
Each uncommon-header cache miss currently builds intermediate strings for uppercase conversion, dash replacement, and the PHP variable prefix and terminator.
Build validated ASCII names in one pass and one allocation with
strings.Builder. Go rejects invalid header names before dispatching HTTP/1 and HTTP/2 requests, so no preliminary ASCII scan or Unicode conversion is needed. Keep the cache and its capacity unchanged.Extend the raw HTTP connection test to verify that names containing spaces, Unicode, invalid UTF-8, or NUL receive HTTP 400 before reaching the handler. Compare conversion against the original expression for valid header names, including all token punctuation, and add a differential fuzz test and a direct conversion benchmark.
Performance reference from the earlier standalone prototype (Go 1.27.3, darwin/arm64, median of five 200ms samples). These measurements include a preliminary ASCII scan that the current revision removes; the current revision has not been benchmarked:
X-Custom-Trace-IdX-CUSTOM-TRACE-IDx-custom-trace-idThese results measure conversion on a cache miss, not cache hits, total request time, or process RSS. Benchmarks were not rerun for this PR.
Validation:
go test -race ./internal/phpheaderspassed.go test ./internal/phpheaders -run '^$' -fuzz '^FuzzHeaderName$' -fuzztime=5spassed 375,900 executions.go vet ./internal/phpheaders,gofmt, andgit diff --checkpassed.Validation in Go's server implementation:
net/http/server.gorejects names failinghttpguts.ValidHeaderFieldName.validWireHeaderFieldName, which checks token characters and lowercase ASCII.