Closed
Description
There is a 128-byte padding in a connection shard structure and there is no any obvious reason for it.
Line 155 in e1bb59c
type ConnShard1 struct {
rmut sync.Mutex
requests [requestsMap]futureList
bufmut sync.Mutex
buf smallWBuf
enc *msgpack.Encoder
_pad [16]uint64 //nolint: unused,structcheck
}
type ConnShard2 struct {
rmut sync.Mutex
requests [requestsMap]futureList
requestsWithCtx [requestsMap]futureList
bufmut sync.Mutex
buf smallWBuf
enc *msgpack.Encoder
_pad [16]uint64 //nolint: unused,structcheck
}
func TestConnShard(t *testing.T) {
v := ConnShard1{}
typ := reflect.TypeOf(v)
fmt.Printf("Type ConnShard1 is %d bytes long\n", typ.Size())
n := typ.NumField()
for i := 0; i < n; i++ {
field := typ.Field(i)
fmt.Printf("%s at offset %v, size=%d, align=%d\n",
field.Name, field.Offset, field.Type.Size(),
field.Type.Align())
}
fmt.Printf("ConnShard1 align is %d\n\n\n", typ.Align())
v2 := ConnShard2{}
typ2 := reflect.TypeOf(v2)
fmt.Printf("Type ConnShard2 is %d bytes long\n", typ2.Size())
n = typ.NumField()
for i := 0; i < n; i++ {
field := typ2.Field(i)
fmt.Printf("%s at offset %v, size=%d, align=%d\n",
field.Name, field.Offset, field.Type.Size(),
field.Type.Align())
}
fmt.Printf("ConnShard2 align is %d\n", typ2.Align())
}
The output:
Type ConnShard1 is 2240 bytes long
rmut at offset 0, size=8, align=4
requests at offset 8, size=2048, align=8
bufmut at offset 2056, size=8, align=4
buf at offset 2064, size=40, align=8
enc at offset 2104, size=8, align=8
_pad at offset 2112, size=128, align=8
ConnShard1 align is 8
Type ConnShard2 is 4288 bytes long
rmut at offset 0, size=8, align=4
requests at offset 8, size=2048, align=8
requestsWithCtx at offset 2056, size=2048, align=8
bufmut at offset 4104, size=8, align=4
buf at offset 4112, size=40, align=8
enc at offset 4152, size=8, align=8
_pad at offset 4160, size=128, align=8
ConnShard2 align is 8
Originally posted by @vr009 in #173 (comment)