transport: optimize header field allocation - #9297
Open
2307vivek wants to merge 1 commit into
Open
Conversation
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9297 +/- ##
==========================================
- Coverage 83.06% 83.03% -0.03%
==========================================
Files 423 423
Lines 35215 35224 +9
==========================================
- Hits 29251 29250 -1
- Misses 4440 4446 +6
- Partials 1524 1528 +4
🚀 New features to boost your workflow:
|
2307vivek
force-pushed
the
optimize_slice_resizing
branch
from
August 7, 2026 09:18
3895d3f to
aaa8589
Compare
Author
|
Gentle ping @mbissa. Also the failing test is not related to these changes. Would appreciate if someone can rerun the checks again. |
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.
In
http2_server.go, bothwriteHeaderLockedandwriteStatusinitialized header field slices with a hard-coded capacity of 2, then appended all metadata values viaappendHeaderFieldsFromMD. With metadata-heavy responses, the slice would double its capacity multiple times, each re-allocation copying all existing elements.This pr pre-sizes header field slices to the exact count of metadata header fields before appending, eliminating repeated slice re-allocations during response header/trailer construction.
Benchmarks
$ go test ./internal/transport/ -bench='BenchmarkAppendHeaderFieldsFromMD' -benchmem -run='^$' -timeout 60sRELEASE NOTES: none