From fff4f599fe1c21e411a99de5c9b3777d06ce0ce6 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Thu, 11 Apr 2019 09:50:59 -0700 Subject: cmd/compile,runtime: allocate defer records on the stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- test/codegen/stack.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/codegen/stack.go') diff --git a/test/codegen/stack.go b/test/codegen/stack.go index ca37622286..37d378aa78 100644 --- a/test/codegen/stack.go +++ b/test/codegen/stack.go @@ -109,3 +109,8 @@ func MightPanic(a []int, i, j, k, s int) { _ = i << s // panicShift _ = i / j // panicDivide } + +func Defer() { + // amd64:`CALL\truntime\.deferprocStack` + defer func() {}() +} -- cgit v1.3-5-g9baa