• 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
asm.go 16.1 KB