Skip to content

Commit 94e61ab

Browse files
tenderloverandall77
authored andcommitted
runtime/runtime2: 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. Change-Id: If555cdaf2f5eaa125e2590fc4d113dbc99750738 GitHub-Last-Rev: d63b4e0 GitHub-Pull-Request: #36552 Reviewed-on: https://go-review.googlesource.com/c/go/+/214677 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 5d9549d commit 94e61ab

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/runtime/export_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ func GetNextArenaHint() uintptr {
483483

484484
type G = g
485485

486+
type Sudog = sudog
487+
486488
func Getg() *G {
487489
return getg()
488490
}

src/runtime/runtime2.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ type sudog struct {
349349

350350
g *g
351351

352-
// isSelect indicates g is participating in a select, so
353-
// g.selectDone must be CAS'd to win the wake-up race.
354-
isSelect bool
355352
next *sudog
356353
prev *sudog
357354
elem unsafe.Pointer // data element (may point to stack)
@@ -364,6 +361,11 @@ type sudog struct {
364361
acquiretime int64
365362
releasetime int64
366363
ticket uint32
364+
365+
// isSelect indicates g is participating in a select, so
366+
// g.selectDone must be CAS'd to win the wake-up race.
367+
isSelect bool
368+
367369
parent *sudog // semaRoot binary tree
368370
waitlink *sudog // g.waiting list or semaRoot
369371
waittail *sudog // semaRoot

src/runtime/sizeof_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestSizeof(t *testing.T) {
2222
_64bit uintptr // size on 64bit platforms
2323
}{
2424
{runtime.G{}, 216, 376}, // g, but exported for testing
25+
{runtime.Sudog{}, 56, 88}, // sudog, but exported for testing
2526
}
2627

2728
for _, tt := range tests {

0 commit comments

Comments
 (0)