-
Notifications
You must be signed in to change notification settings - Fork 112
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
Optimize header access #445
Optimize header access #445
Conversation
There are a lot of attempts to directly set header values already, this unifies all Get/Set/Add/Del accesses to assume a canonical form already. In my personal testings, this actually stands out in our hot paths in flame graphs doing header Get/Sets. Within this codebase, we already have constants in place already in the correct formats. I've dug so deeply into this in the past that I created https://github.com/mattrobenolt/go-httpheaders which specifically highlights benchmarks of direct access vs using the Get/Set helpers. Since these are called multiple times in very hot paths, it's a worthwhile optimization since we can trust the inputs.
@@ -37,6 +37,7 @@ const ( | |||
const ( | |||
headerContentType = "Content-Type" | |||
headerUserAgent = "User-Agent" | |||
headerTrailer = "Trailer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured since this was referenced multiple times, might as well elevate it to a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great - thank you! I pushed a commit that changes the "XXX:" comments to match Buf's style a bit better, but the remainder of the change is excellent.
Perfect, those comments were more for yall while reviewing anyways, since I wasn't entirely sure if my assumption was true or not. |
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/bufbuild/connect-go](https://togithub.com/bufbuild/connect-go) | require | patch | `v1.5.0` -> `v1.5.1` | --- ### Release Notes <details> <summary>bufbuild/connect-go</summary> ### [`v1.5.1`](https://togithub.com/bufbuild/connect-go/releases/tag/v1.5.1) [Compare Source](https://togithub.com/bufbuild/connect-go/compare/v1.5.0...v1.5.1) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed Thanks to [@​mattrobenolt](https://togithub.com/mattrobenolt), v1.5.1 exclusively contains performance improvements. There should be no other user-visible behavior changes. ##### Bugfixes - Minimize allocations writing User-Agent header by [@​mattrobenolt](https://togithub.com/mattrobenolt) in [https://github.com/bufbuild/connect-go/pull/446](https://togithub.com/bufbuild/connect-go/pull/446) - Minimize allocations parsing Content-Type by [@​mattrobenolt](https://togithub.com/mattrobenolt) in [https://github.com/bufbuild/connect-go/pull/444](https://togithub.com/bufbuild/connect-go/pull/444) - Optimize header access by [@​mattrobenolt](https://togithub.com/mattrobenolt) in [https://github.com/bufbuild/connect-go/pull/445](https://togithub.com/bufbuild/connect-go/pull/445) - Optimize Peer lookups by [@​mattrobenolt](https://togithub.com/mattrobenolt) in [https://github.com/bufbuild/connect-go/pull/447](https://togithub.com/bufbuild/connect-go/pull/447) **Full Changelog**: bufbuild/connect-go@v1.5.0...v1.5.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/open-feature/flagd). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTkuMCIsInVwZGF0ZWRJblZlciI6IjM0LjExOS4wIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
The standard library's `http.Header.{Get,Set,Add,Del}` automatically canonicalize header keys. This is nice, but expensive for us - we're using these APIs in many hot paths, and our constants are already in canonical form. This PR adds functions that bypass canonicalization and uses them wherever possible. --------- Co-authored-by: Akshay Shah <[email protected]>
There are a lot of attempts to directly set header values already, this unifies all Get/Set/Add/Del accesses to assume a canonical form already.
In my personal testings, this actually stands out in our hot paths in flame graphs doing header Get/Sets. Within this codebase, we already have constants in place already in the correct formats.
I've dug so deeply into this in the past that I created https://github.com/mattrobenolt/go-httpheaders which specifically highlights benchmarks of direct access vs using the Get/Set helpers.
Since these are called multiple times in very hot paths, it's a worthwhile optimization since we can trust the inputs.
Before submitting your PR: Please read through the contribution guide at https://github.com/bufbuild/connect-go/blob/main/.github/CONTRIBUTING.md