]> Cypherpunks repositories - gostls13.git/commit
cmd/link: fewer allocs in ld.Arch.Archreloc
authorisharipo <iskander.sharipov@intel.com>
Thu, 17 May 2018 16:50:29 +0000 (19:50 +0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 20 Aug 2018 22:10:31 +0000 (22:10 +0000)
commit328adf9d62b681bf4f7cb0c41a3f16272cf5f4a2
treed858726c5608eff637d6f7f74eab18fadf94838d
parent4201c2077ec3446a4fea5ed768c82aa96df69233
cmd/link: fewer allocs in ld.Arch.Archreloc

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: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/mips/asm.go
src/cmd/link/internal/mips64/asm.go
src/cmd/link/internal/ppc64/asm.go
src/cmd/link/internal/s390x/asm.go
src/cmd/link/internal/x86/asm.go