diff options
author | Keith Randall <keithr@alum.mit.edu> | 2019-04-11 09:50:59 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-06-04 17:35:20 +0000 |
commit | fff4f599fe1c21e411a99de5c9b3777d06ce0ce6 (patch) | |
tree | 8e048033606759d2e1ad5bb11085a5188ba3cdd0 /test/live.go | |
parent | 8343a0934df8f437938c55a6f0ff120c7c24a8bb (diff) | |
download | go-fff4f599fe1c21e411a99de5c9b3777d06ce0ce6.tar.gz go-fff4f599fe1c21e411a99de5c9b3777d06ce0ce6.zip |
cmd/compile,runtime: allocate defer records on the stack
When a defer is executed at most once in a function body,
we can allocate the defer record for it on the stack instead
of on the heap.
This should make defers like this (which are very common) faster.
This optimization applies to 363 out of the 370 static defer sites
in the cmd/go binary.
name old time/op new time/op delta
Defer-4 52.2ns ± 5% 36.2ns ± 3% -30.70% (p=0.000 n=10+10)
Fixes #6980
Update #14939
Change-Id: I697109dd7aeef9e97a9eeba2ef65ff53d3ee1004
Reviewed-on: https://go-review.googlesource.com/c/go/+/171758
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'test/live.go')
-rw-r--r-- | test/live.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/test/live.go b/test/live.go index e7134eca0c..ec51193725 100644 --- a/test/live.go +++ b/test/live.go @@ -687,7 +687,7 @@ type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "li // In particular, at printint r must be live. func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$" r = p - defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$" + defer func() { // ERROR "live at call to deferprocStack: q r$" "live at call to deferreturn: r$" recover() }() printint(0) // ERROR "live at call to printint: q r$" |