mirror of
https://github.com/golang/go
synced 2024-11-18 14:04:45 -07:00
runtime: do not allocate on every time.Sleep
It's common for some goroutines to loop calling time.Sleep. Allocate once per goroutine, not every time. This comes up in runtime/pprof's background reader. Change-Id: I89d17dc7379dca266d2c9cd3aefc2382f5bdbade Reviewed-on: https://go-review.googlesource.com/37162 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
a1ea91219f
commit
a1261b8b0a
@ -2330,6 +2330,7 @@ func goexit0(gp *g) {
|
||||
gp.waitreason = ""
|
||||
gp.param = nil
|
||||
gp.labels = nil
|
||||
gp.timer = nil
|
||||
|
||||
// Note that gp's stack scan is now "valid" because it has no
|
||||
// stack.
|
||||
|
@ -376,6 +376,7 @@ type g struct {
|
||||
waiting *sudog // sudog structures this g is waiting on (that have a valid elem ptr); in lock order
|
||||
cgoCtxt []uintptr // cgo traceback context
|
||||
labels unsafe.Pointer // profiler labels
|
||||
timer *timer // cached timer for time.Sleep
|
||||
|
||||
// Per-G GC state
|
||||
|
||||
|
@ -50,7 +50,12 @@ func timeSleep(ns int64) {
|
||||
return
|
||||
}
|
||||
|
||||
t := new(timer)
|
||||
t := getg().timer
|
||||
if t == nil {
|
||||
t = new(timer)
|
||||
getg().timer = t
|
||||
}
|
||||
*t = timer{}
|
||||
t.when = nanotime() + ns
|
||||
t.f = goroutineReady
|
||||
t.arg = getg()
|
||||
|
Loading…
Reference in New Issue
Block a user