-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/net/http/httpguts: validation of header names, methods, and cookie names could be about twice as fast #66700
Comments
@dmitshur This would be my first contribution to Go; I'm still learning the ropes. My understanding of the NeedsInvestigation tag and of the contribution guide is that I should wait for other people to chime in here before sending a PR. Correct? |
cc @neild |
@jub0bs Yes, your understanding is right and generally it's good to allow some time for discussion on the issue first, though it's still okay to send a change sooner. There are some more details about the intended use of labels at https://go.dev/wiki/HandlingIssues#issue-states. Thanks. |
I'm happy to review a CL if you want to send me one. For purely changes that have no behavioral impact and don't add new API surface, it's generally fine to just send a CL without opening an issue. (Sounds like you might be proposing a new function in |
Change https://go.dev/cl/578075 mentions this issue: |
@neild Thanks! I did float the idea of augmenting Perhaps we should first see if my proposed speedup of |
Go version
go1.22.2
golang/x/net v0.24.0
Output of
go env
in your module/workspace:What did you do?
I noticed that
httpguts.IsTokenRune
, whichhttpguts.ValidHeaderFieldName
calls iteratively and which net/http in general relies on, systematically incurs a bounds check. I then wrote an alternative implementation that eliminates those bounds checks and also obviates the need for UTF-8 decoding.What did you see happen?
Benchmarks indicate that my implementation is about twice as fast as the current one; see below.
Moreover, the same logic could be used to validate HTTP methods and cookie names in addition to HTTP header-field names, since all three share the same production (token). At the moment, their validation logic, because it relies on
strings.IndexFunc
andhttpguts.IsTokenRune
, isn't as fast as it could, as shown by one of my benchmarks./cc @bradfitz @neild
What did you expect to see?
I expected at least some speedup of
httpguts.ValidHeaderFieldName
.I have not yet checked how such a change would affect the performance of net/http, though.
The text was updated successfully, but these errors were encountered: