Skip to content

Commit 6e97c71

Browse files
committed
cmd/internal/obj: split Link.hash into version 0 and 1
Though LSym.Version is an int, it can only have the value 0 or 1. Using that, split Link.hash into two maps, one for version 0 (which is far more common) and one for version 1. This lets use just the name for lookups, which is both faster and more compact. This matters because Link.hash map lookups are frequent, and will be contended once the backend is concurrent. name old time/op new time/op delta Template 194ms ± 3% 192ms ± 5% -1.46% (p=0.000 n=47+49) Unicode 84.5ms ± 3% 83.8ms ± 3% -0.81% (p=0.011 n=50+49) GoTypes 543ms ± 2% 545ms ± 4% ~ (p=0.566 n=46+49) Compiler 2.48s ± 2% 2.48s ± 3% ~ (p=0.706 n=47+50) SSA 5.94s ± 3% 5.98s ± 2% +0.55% (p=0.040 n=49+50) Flate 119ms ± 6% 119ms ± 4% ~ (p=0.681 n=48+47) GoParser 145ms ± 4% 145ms ± 3% ~ (p=0.662 n=47+49) Reflect 348ms ± 3% 344ms ± 3% -1.17% (p=0.000 n=47+47) Tar 105ms ± 4% 104ms ± 3% ~ (p=0.155 n=50+47) XML 197ms ± 2% 197ms ± 3% ~ (p=0.666 n=49+49) [Geo mean] 332ms 331ms -0.37% name old user-time/op new user-time/op delta Template 230ms ±10% 226ms ±10% -1.85% (p=0.041 n=50+50) Unicode 104ms ± 6% 103ms ± 5% ~ (p=0.076 n=49+49) GoTypes 707ms ± 4% 705ms ± 5% ~ (p=0.521 n=50+50) Compiler 3.30s ± 3% 3.33s ± 4% +0.76% (p=0.003 n=50+49) SSA 8.17s ± 4% 8.23s ± 3% +0.66% (p=0.030 n=50+49) Flate 139ms ± 6% 138ms ± 8% ~ (p=0.184 n=49+48) GoParser 174ms ± 5% 172ms ± 6% ~ (p=0.107 n=48+49) Reflect 431ms ± 8% 420ms ± 5% -2.57% (p=0.000 n=50+46) Tar 119ms ± 6% 118ms ± 7% -0.95% (p=0.033 n=50+49) XML 236ms ± 4% 236ms ± 4% ~ (p=0.935 n=50+48) [Geo mean] 410ms 407ms -0.67% name old alloc/op new alloc/op delta Template 38.7MB ± 0% 38.6MB ± 0% -0.29% (p=0.008 n=5+5) Unicode 29.8MB ± 0% 29.7MB ± 0% -0.24% (p=0.008 n=5+5) GoTypes 113MB ± 0% 113MB ± 0% -0.29% (p=0.008 n=5+5) Compiler 462MB ± 0% 462MB ± 0% -0.12% (p=0.008 n=5+5) SSA 1.27GB ± 0% 1.27GB ± 0% -0.05% (p=0.008 n=5+5) Flate 25.2MB ± 0% 25.1MB ± 0% -0.37% (p=0.008 n=5+5) GoParser 31.7MB ± 0% 31.6MB ± 0% ~ (p=0.056 n=5+5) Reflect 77.5MB ± 0% 77.2MB ± 0% -0.38% (p=0.008 n=5+5) Tar 26.4MB ± 0% 26.3MB ± 0% ~ (p=0.151 n=5+5) XML 41.9MB ± 0% 41.9MB ± 0% -0.20% (p=0.032 n=5+5) [Geo mean] 74.5MB 74.3MB -0.23% name old allocs/op new allocs/op delta Template 378k ± 1% 377k ± 1% ~ (p=0.690 n=5+5) Unicode 321k ± 0% 322k ± 0% ~ (p=0.595 n=5+5) GoTypes 1.14M ± 0% 1.14M ± 0% ~ (p=0.310 n=5+5) Compiler 4.25M ± 0% 4.25M ± 0% ~ (p=0.151 n=5+5) SSA 9.84M ± 0% 9.84M ± 0% ~ (p=0.841 n=5+5) Flate 232k ± 1% 232k ± 0% ~ (p=0.690 n=5+5) GoParser 315k ± 1% 315k ± 1% ~ (p=0.841 n=5+5) Reflect 970k ± 0% 970k ± 0% ~ (p=0.841 n=5+5) Tar 248k ± 0% 248k ± 1% ~ (p=0.841 n=5+5) XML 389k ± 0% 389k ± 0% ~ (p=1.000 n=5+5) [Geo mean] 724k 724k +0.01% Updates #15756 Change-Id: I2646332e89f0444ca9d5a41d7172537d904ed636 Reviewed-on: https://go-review.googlesource.com/41050 Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 7189a02 commit 6e97c71

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/cmd/internal/obj/line_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212

1313
func TestLinkgetlineFromPos(t *testing.T) {
1414
ctxt := new(Link)
15-
ctxt.hash = make(map[SymVer]*LSym)
15+
ctxt.hash = make(map[string]*LSym)
16+
ctxt.vhash = make(map[string]*LSym)
1617

1718
afile := src.NewFileBase("a.go", "a.go")
1819
bfile := src.NewFileBase("b.go", "/foo/bar/b.go")

src/cmd/internal/obj/link.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ type Link struct {
480480
Flag_optimize bool
481481
Bso *bufio.Writer
482482
Pathname string
483-
hash map[SymVer]*LSym
483+
hash map[string]*LSym // name -> sym mapping for version == 0
484+
vhash map[string]*LSym // name -> sym mapping for version == 1
484485
PosTable src.PosTable
485486
InlTree InlTree // global inlining tree used by gc/inl.go
486487
Imports []string
@@ -522,11 +523,6 @@ func (ctxt *Link) FixedFrameSize() int64 {
522523
}
523524
}
524525

525-
type SymVer struct {
526-
Name string
527-
Version int // TODO: make int16 to match LSym.Version?
528-
}
529-
530526
// LinkArch is the definition of a single architecture.
531527
type LinkArch struct {
532528
*sys.Arch

src/cmd/internal/obj/sym.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import (
4040

4141
func Linknew(arch *LinkArch) *Link {
4242
ctxt := new(Link)
43-
ctxt.hash = make(map[SymVer]*LSym)
43+
ctxt.hash = make(map[string]*LSym)
44+
ctxt.vhash = make(map[string]*LSym)
4445
ctxt.Arch = arch
4546
ctxt.Pathname = objabi.WorkingDir()
4647

@@ -63,13 +64,21 @@ func (ctxt *Link) Lookup(name string, v int) *LSym {
6364
// LookupInit looks up the symbol with name name and version v.
6465
// If it does not exist, it creates it and passes it to initfn for one-time initialization.
6566
func (ctxt *Link) LookupInit(name string, v int, init func(s *LSym)) *LSym {
66-
s := ctxt.hash[SymVer{name, v}]
67-
if s != nil {
67+
var m map[string]*LSym
68+
switch v {
69+
case 0:
70+
m = ctxt.hash
71+
case 1:
72+
m = ctxt.vhash
73+
default:
74+
ctxt.Diag("LookupInit: bad version %d", v)
75+
}
76+
if s := m[name]; s != nil {
6877
return s
6978
}
7079

71-
s = &LSym{Name: name, Version: int16(v)}
72-
ctxt.hash[SymVer{name, v}] = s
80+
s := &LSym{Name: name, Version: int16(v)}
81+
m[name] = s
7382
if init != nil {
7483
init(s)
7584
}

0 commit comments

Comments
 (0)