stream: group bool fields at tail of clientStream to reduce allocator size class 288B→256B - #9281
Open
gidotencate wants to merge 2 commits into
Open
stream: group bool fields at tail of clientStream to reduce allocator size class 288B→256B#9281gidotencate wants to merge 2 commits into
gidotencate wants to merge 2 commits into
Conversation
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9281 +/- ##
==========================================
+ Coverage 83.05% 83.14% +0.09%
==========================================
Files 422 422
Lines 35040 35044 +4
==========================================
+ Hits 29101 29139 +38
+ Misses 4427 4403 -24
+ Partials 1512 1502 -10
🚀 New features to boost your workflow:
|
gidotencate
force-pushed
the
stream-clientstream-group-bools
branch
from
July 30, 2026 21:48
9ed2533 to
83e2471
Compare
easwars
reviewed
Jul 30, 2026
clientStream had 7 bool fields scattered among pointer- and int-sized fields, creating ~40 bytes of alignment padding and placing the struct in the 288-byte allocator size class (280 B struct → 288 B class). Grouping all bools at the tail packs them contiguously (7 B + 1 B tail pad) and reduces the struct to 248 B, which fits in the 256-byte size class: 32 B saved unconditionally per RPC stream, ~10.8% less GC pressure at scale. Lock discipline is preserved with explicit "Not guarded by mu" / "Guarded by mu" section comments within the bool group. A TestClientStreamSize test guards against future growth back across the class boundary; new bool fields should be added to the grouped section, not inline. Benchmarks, cache-line analysis, and the rejected "surgical" alternative (placing mu-guarded bools adjacent to mu caused 20-22% slowdowns from false sharing on CL2) are documented in the linked issue. Fixes grpc#9280
gidotencate
force-pushed
the
stream-clientstream-group-bools
branch
from
July 30, 2026 22:00
83e2471 to
9f84105
Compare
Open
2 tasks
easwars
approved these changes
Aug 17, 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.
Reorder
clientStreamfields so all 7 bool fields are grouped at the tail of the struct. Add(s).TestClientStreamSizeto guard against regressions.Why
clientStreamhad 7boolfields scattered among pointer- and int-sized fields. Each bool was followed by 3–7 bytes of alignment padding before the next 4- or 8-byte-aligned field, totalling ~40 bytes of wasted padding:sentLast+receivedFirstMsg(together)serverHeaderBinloggedsync.Mutex, align 4)firstAttemptint, align 8)finishedcommittedfunc(), align 8)nameResolutionDelayResult: 280 B struct → 288 B allocator size class.
Grouping all bools at the tail packs them into 7 B + 1 B tail pad = 8 B, reducing the struct to 248 B → 256 B allocator size class: 32 B saved per RPC stream unconditionally, ~10.8% less GC pressure at scale (benchmarks in #9280).
Code clarity
Lock discipline is preserved explicitly: the bool group is split into
// Not guarded by muand// Guarded by musections with per-field comments matching the original. A comment in the struct explains the layout rationale and points to #9280.(s).TestClientStreamSizegives a clear error message directing future contributors to add new bool fields in the grouped section.Closes #9280
RELEASE NOTES:
clientStreambool fields to reduce struct size from the 288-byte to the 256-byte allocator size class, saving 32 bytes per RPC stream.