1
0
mirror of https://github.com/golang/go synced 2024-11-23 14:50:07 -07:00

Pack the sudog struct

This commit moves the isSelect bool below the ticket uint32.  The
boolean was consuming 8 bytes of the struct.  The uint32 was also
consuming 8 bytes, so we can pack isSelect below the uint32 and save 8
bytes.

This reduces the sudog struct from 96 bytes to 88 bytes.
This commit is contained in:
Aaron Patterson 2020-01-14 09:09:01 -08:00
parent 0c65531ef1
commit d63b4e086b
No known key found for this signature in database
GPG Key ID: 953170BCB4FFAFC6
3 changed files with 8 additions and 3 deletions

View File

@ -483,6 +483,8 @@ func GetNextArenaHint() uintptr {
type G = g
type Sudog = sudog
func Getg() *G {
return getg()
}

View File

@ -346,9 +346,6 @@ type sudog struct {
g *g
// isSelect indicates g is participating in a select, so
// g.selectDone must be CAS'd to win the wake-up race.
isSelect bool
next *sudog
prev *sudog
elem unsafe.Pointer // data element (may point to stack)
@ -361,6 +358,11 @@ type sudog struct {
acquiretime int64
releasetime int64
ticket uint32
// isSelect indicates g is participating in a select, so
// g.selectDone must be CAS'd to win the wake-up race.
isSelect bool
parent *sudog // semaRoot binary tree
waitlink *sudog // g.waiting list or semaRoot
waittail *sudog // semaRoot

View File

@ -22,6 +22,7 @@ func TestSizeof(t *testing.T) {
_64bit uintptr // size on 64bit platforms
}{
{runtime.G{}, 216, 376}, // g, but exported for testing
{runtime.Sudog{}, 56, 88}, // sudog, but exported for testing
}
for _, tt := range tests {