Skip to content

Commit b77c4e2

Browse files
committed
wip: add fastfastpath
name old time/op new time/op delta SelectUncontended-6 15.2ns ±11% 11.3ns ±12% -25.92% (p=0.000 n=10+10) SelectSyncContended-6 1.16µs ± 6% 1.34µs ± 2% +15.99% (p=0.000 n=10+9) SelectAsyncContended-6 124ns ± 3% 90ns ± 1% -27.51% (p=0.000 n=10+9) SelectNonblock-6 3.16ns ± 6% 3.25ns ± 4% +2.96% (p=0.020 n=10+9) SelectProdCons-6 460ns ± 7% 280ns ± 4% -39.14% (p=0.000 n=10+10) GoroutineSelect-6 1.49ms ± 3% 1.50ms ± 3% ~ (p=0.684 n=10+10) Change-Id: I5a02ef5f458c88ac26079abfec3b6a0f95d6e023
1 parent f47004f commit b77c4e2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/runtime/select.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package runtime
77
// This file contains the implementation of Go select statements.
88

99
import (
10+
"runtime/internal/atomic"
1011
"unsafe"
1112
)
1213

@@ -173,12 +174,16 @@ func selectgo(cas0 *scase, order0 *uint16, ncases int) (int, bool) {
173174
cas := scases[n]
174175
switch cas.kind {
175176
case caseRecv:
176-
// TODO: lift/outline the fast path checks from chanrecv
177+
if empty(cas.c) && atomic.Load(&cas.c.closed) == 0 {
178+
continue
179+
}
177180
if selected, received := chanrecv(cas.c, cas.elem, false); selected {
178181
return n, received
179182
}
180183
case caseSend:
181-
// TODO: lift/outline the fast path checks from chansend
184+
if cas.c.closed == 0 && full(cas.c) {
185+
continue
186+
}
182187
if chansend(cas.c, cas.elem, false, cas.pc) {
183188
return n, false
184189
}

0 commit comments

Comments
 (0)