• isharipo's avatar
    cmd/link: fewer allocs in ld.Arch.Archreloc · 328adf9d
    isharipo authored
    Archreloc had this signature:
    
    	func(*Link, *sym.Reloc, *sym.Symbol, *int64) bool
    
    The last *int64 argument is used as out parameter.
    Passed valus could be allocated on stack, but escape analysis
    fails here, leading to high number of unwanted allocs.
    
    If instead 4th arg is passed by value, and modified values is returned,
    no problems with allocations arise:
    
    	func(*Link, *sym.Reloc, *sym.Symbol, int64) (int64, bool)
    
    There are 2 benefits:
    1. code becomes more readable.
    2. less allocations.
    
    For linking "hello world" example from net/http:
    
    	name      old time/op  new time/op  delta
    	Linker-4   530ms ± 2%   520ms ± 2%  -1.83%  (p=0.001 n=17+16)
    
    It's top 1 in alloc_objects from memprofile:
    
    	flat   flat%  sum%       cum    cum%
    	229379 33.05% 33.05%     229379 33.05%  cmd/link/internal/ld.relocsym
    	...
    
    list relocsym:
    
    	229379     229379 (flat, cum) 33.05% of Total
    	229379     229379    183:    var o int64
    
    After the patch, ~230k of int64 allocs (~ 1.75mb) removed.
    
    Passes toolshash-check (toolstash cmp).
    
    Change-Id: I25504fe27967bcff70c4b7338790f3921d15473d
    Reviewed-on: https://go-review.googlesource.com/113637
    Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    328adf9d
Name
Last commit
Last update
..
addr2line Loading commit data...
api Loading commit data...
asm Loading commit data...
buildid Loading commit data...
cgo Loading commit data...
compile Loading commit data...
cover Loading commit data...
dist Loading commit data...
doc Loading commit data...
fix Loading commit data...
go Loading commit data...
gofmt Loading commit data...
internal Loading commit data...
link Loading commit data...
nm Loading commit data...
objdump Loading commit data...
pack Loading commit data...
pprof Loading commit data...
test2json Loading commit data...
trace Loading commit data...
vendor Loading commit data...
vet Loading commit data...