Skip to content

Commit 852e985

Browse files
committed
stream: group bool fields at tail of addrConnStream to reduce allocator size class
Four bool fields in addrConnStream were scattered among pointer- and interface-sized fields, each forcing alignment padding before the next field: sentLast + receivedFirstMsg @ 96-97 6 B padding (before 8B-aligned pointer) decompressorSet @ 160 7 B padding (before 16B-aligned interface) finished @ 248 7 B tail padding Total: 20 B interior padding, 16 B net savings when all bools are moved to the tail. addrConnStream shrinks from 256 B to 240 B, dropping from the 256 B to the 240 B allocator size class. Fixes #9348
1 parent 9d1988d commit 852e985

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

stream.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,19 +1498,28 @@ type addrConnStream struct {
14981498
callInfo *callInfo
14991499
transport transport.ClientTransport
15001500
ctx context.Context
1501-
sentLast bool
1502-
receivedFirstMsg bool
15031501
desc *StreamDesc
15041502
codec baseCodec
15051503
sendCompressorV0 Compressor
15061504
sendCompressorV1 encoding.Compressor
1507-
decompressorSet bool
15081505
decompressorV0 Decompressor
15091506
decompressorV1 encoding.Compressor
15101507
parser parser
15111508

15121509
// mu guards finished and is held for the entire finish method.
1513-
mu sync.Mutex
1510+
mu sync.Mutex
1511+
1512+
// Bool fields are grouped at the tail to eliminate the alignment padding
1513+
// that would otherwise follow each bool when the next field is pointer- or
1514+
// int-sized. See https://github.com/grpc/grpc-go/issues/9348 for benchmarks.
1515+
// Add new bool fields here, not inline above.
1516+
1517+
// Not guarded by mu.
1518+
sentLast bool
1519+
receivedFirstMsg bool
1520+
decompressorSet bool
1521+
1522+
// Guarded by mu.
15141523
finished bool
15151524
}
15161525

0 commit comments

Comments
 (0)