cmd/link/internal/ld: avoid Reloc copies in range loops

Copying sym.Reloc in loops hurts performance as
it has 48 byte size (on 64-bit platforms).

There are quite many symbols and each of them has more than 1
relocation (so, it's possible to have more than 1kk relocs).
The're also traversed more than once in some code paths.

By using pointers to them, copies are avoided.

For linking "hello world" example from net/http:

	name      old time/op  new time/op  delta
	Linker-4   530ms ± 2%   521ms ± 3%  -1.80%  (p=0.000 n=17+20)

Change-Id: I6518aec69d6adcd137f84b5c089ceab4cb4ea2dd
Reviewed-on: https://go-review.googlesource.com/113636
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
isharipo 2018-05-17 19:47:52 +03:00 committed by Brad Fitzpatrick
parent 97c7e0e0ad
commit bc276c585b
5 changed files with 14 additions and 8 deletions

View file

@ -503,7 +503,8 @@ func (ctxt *Link) loadlib() {
// objects, try to read them from the libgcc file.
any := false
for _, s := range ctxt.Syms.Allsym {
for _, r := range s.R {
for i := range s.R {
r := &s.R[i] // Copying sym.Reloc has measurable impact on peformance
if r.Sym != nil && r.Sym.Type == sym.SXREF && r.Sym.Name != ".got" {
any = true
break