Commit d79aea6b authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/link: deduplicate pctab info in pclntab

The existing pclntab construction took care to re-use strings:
filenames and fully qualified function names.

It did not try to deduplicate pctab information,
perhaps because the author assumed that there
wouldn't be much duplication.

This change introduces that deduplication.
The cache gets a 33% hit rate during make.bash.

This doesn't require any changes to the file format,
and shrinks binaries by about 1%.

Updates #6853

file      before    after     Δ        %       
go        14659236  14515876  -143360  -0.978% 
addr2line 4272424   4223272   -49152   -1.150% 
api       6050808   5993464   -57344   -0.948% 
asm       4906416   4869552   -36864   -0.751% 
buildid   2861104   2824240   -36864   -1.288% 
cgo       4859784   4810632   -49152   -1.011% 
compile   25749656  25213080  -536576  -2.084% 
cover     5286952   5229608   -57344   -1.085% 
dist      3634192   3597328   -36864   -1.014% 
doc       4691080   4641928   -49152   -1.048% 
fix       3397960   3361096   -36864   -1.085% 
link      6113568   6064432   -49136   -0.804% 
nm        4221928   4172776   -49152   -1.164% 
objdump   4636600   4587448   -49152   -1.060% 
pack      2281184   2256608   -24576   -1.077% 
pprof     14641204  14485556  -155648  -1.063% 
test2json 2814536   2785864   -28672   -1.019% 
trace     11602204  11487516  -114688  -0.989% 
vet       8399528   8313512   -86016   -1.024% 

Change-Id: I59c6aae522700a0d36ddd2cbca6e22ecdf17eea2
Reviewed-on: https://go-review.googlesource.com/c/go/+/172079
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d3a23874
...@@ -82,15 +82,6 @@ func (it *PCIter) init(p []byte) { ...@@ -82,15 +82,6 @@ func (it *PCIter) init(p []byte) {
it.next() it.next()
} }
func addpctab(ctxt *Link, ftab *sym.Symbol, off int32, d *sym.Pcdata) int32 {
var start int32
if len(d.P) > 0 {
start = int32(len(ftab.P))
ftab.AddBytes(d.P)
}
return int32(ftab.SetUint32(ctxt.Arch, int64(off), uint32(start)))
}
func ftabaddstring(ftab *sym.Symbol, s string) int32 { func ftabaddstring(ftab *sym.Symbol, s string) int32 {
start := len(ftab.P) start := len(ftab.P)
ftab.Grow(int64(start + len(s) + 1)) // make room for s plus trailing NUL ftab.Grow(int64(start + len(s) + 1)) // make room for s plus trailing NUL
...@@ -239,6 +230,20 @@ func (ctxt *Link) pclntab() { ...@@ -239,6 +230,20 @@ func (ctxt *Link) pclntab() {
return nameoff return nameoff
} }
pctaboff := make(map[string]uint32)
writepctab := func(off int32, p []byte) int32 {
start, ok := pctaboff[string(p)]
if !ok {
if len(p) > 0 {
start = uint32(len(ftab.P))
ftab.AddBytes(p)
}
pctaboff[string(p)] = start
}
newoff := int32(ftab.SetUint32(ctxt.Arch, int64(off), start))
return newoff
}
nfunc = 0 // repurpose nfunc as a running index nfunc = 0 // repurpose nfunc as a running index
for _, s := range ctxt.Textp { for _, s := range ctxt.Textp {
if !emitPcln(ctxt, s) { if !emitPcln(ctxt, s) {
...@@ -370,10 +375,9 @@ func (ctxt *Link) pclntab() { ...@@ -370,10 +375,9 @@ func (ctxt *Link) pclntab() {
} }
// pcdata // pcdata
off = addpctab(ctxt, ftab, off, &pcln.Pcsp) off = writepctab(off, pcln.Pcsp.P)
off = writepctab(off, pcln.Pcfile.P)
off = addpctab(ctxt, ftab, off, &pcln.Pcfile) off = writepctab(off, pcln.Pcline.P)
off = addpctab(ctxt, ftab, off, &pcln.Pcline)
off = int32(ftab.SetUint32(ctxt.Arch, int64(off), uint32(len(pcln.Pcdata)))) off = int32(ftab.SetUint32(ctxt.Arch, int64(off), uint32(len(pcln.Pcdata))))
// funcID uint8 // funcID uint8
...@@ -391,7 +395,7 @@ func (ctxt *Link) pclntab() { ...@@ -391,7 +395,7 @@ func (ctxt *Link) pclntab() {
// nfuncdata must be the final entry. // nfuncdata must be the final entry.
off = int32(ftab.SetUint8(ctxt.Arch, int64(off), uint8(len(pcln.Funcdata)))) off = int32(ftab.SetUint8(ctxt.Arch, int64(off), uint8(len(pcln.Funcdata))))
for i := range pcln.Pcdata { for i := range pcln.Pcdata {
off = addpctab(ctxt, ftab, off, &pcln.Pcdata[i]) off = writepctab(off, pcln.Pcdata[i].P)
} }
// funcdata, must be pointer-aligned and we're only int32-aligned. // funcdata, must be pointer-aligned and we're only int32-aligned.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment