Repository navigation
Conversation
getRawQueryParam now skips a segment whose raw key is shorter than the name before it unescapes the key, because unescaping never makes a key longer. It also splits segments with strings.IndexByte, and checks for an empty segment or a ';' only after the key matches. The result does not change.
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.
What
getRawQueryParamunescaped the key of each segment before it compared the key with the name. Now it skips a segment when the raw key is shorter than the name, because unescaping never makes a key longer. It also splits segments withstrings.IndexByte. It checks for an empty segment or a;only after the key matches.The result does not change.
TestGetRawQueryParamMatchesStdlibgets two cases for the length check: an escaped key that matches, and keys that are longer or shorter than the name.Numbers
amd64 (Intel Xeon Platinum 8573C, Go 1.27.3), 24 interleaved rounds, benchstat:
QueryParam_FastPathc.QueryParam("page"), 4 pairsna%6DeAllocations do not change.
I measured 36 benchmarks in three code layouts, with
getRawQueryParammoved by 0, 9 and 19 bytes. 21 query rows were faster in all three layouts. No row was slower in all three layouts. In layout 0, fiveServeHTTProws were 6% to 16% slower. In the other two layouts, the same rows were 5% to 15% faster. These benchmarks do not callgetRawQueryParam. On Apple M5 (Go 1.26.5, 20 rounds), no row was slower.Checks:
go test -race ./...passes. Go 1.25.0 also passes.staticcheck ./...andgolint ./...show no issues.QueryParam,QueryParams,Bindand routing matched on 1.1M random inputs.