• Keith Randall's avatar
    cmd/compile,runtime: allocate defer records on the stack · fff4f599
    Keith Randall authored
    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: default avatarAustin Clements <austin@google.com>
    fff4f599
traceback.go 43.2 KB