]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile,runtime: allocate defer records on the stack
authorKeith Randall <keithr@alum.mit.edu>
Thu, 11 Apr 2019 16:50:59 +0000 (09:50 -0700)
committerKeith Randall <khr@golang.org>
Tue, 4 Jun 2019 17:35:20 +0000 (17:35 +0000)
commitfff4f599fe1c21e411a99de5c9b3777d06ce0ce6
tree8e048033606759d2e1ad5bb11085a5188ba3cdd0
parent8343a0934df8f437938c55a6f0ff120c7c24a8bb
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>
15 files changed:
src/cmd/compile/internal/gc/esc.go
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/ssa.go
src/runtime/mgcmark.go
src/runtime/panic.go
src/runtime/runtime2.go
src/runtime/stack.go
src/runtime/stack_test.go
src/runtime/stubs.go
src/runtime/syscall_windows.go
src/runtime/traceback.go
test/codegen/stack.go
test/live.go