From: Matthew Dempsky Date: Wed, 26 Jul 2017 18:03:45 +0000 (-0700) Subject: cmd/compile: discard duplicate inline method bodies X-Git-Tag: go1.10beta1~1675 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f0b36269041eff3b8bbdd18e2ff41b06557235d1;p=gostls13.git cmd/compile: discard duplicate inline method bodies If we've already imported a named type, then there's no need to process its associated methods except to validate that the signature matches the existing known method. However, the current import code still creates a new function node for each method, saves its inline body (if any), and adds the node to the global importlist. Because of this, the duplicate methods are never garbage collected. This CL changes the compiler to avoid amassing uncollectable garbage or performing any unnecessary processing. This is particularly noticeable for protobuf-heavy code. For the motivating Go package, this CL reduced compile max-RSS from ~12GB to ~3GB and compile time from ~65s to ~50s. Passes toolstash -cmp for std, cmd, and k8s.io/kubernetes/cmd/.... Change-Id: Ib53ba9f2ad3212995671cf6ba220ee8a56d8d009 Reviewed-on: https://go-review.googlesource.com/51331 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- diff --git a/src/cmd/compile/internal/gc/bimport.go b/src/cmd/compile/internal/gc/bimport.go index 2962962089..8cc8903dcd 100644 --- a/src/cmd/compile/internal/gc/bimport.go +++ b/src/cmd/compile/internal/gc/bimport.go @@ -484,6 +484,7 @@ func (p *importer) typ() *types.Type { t = pkgtype(p.imp, tsym) p.typList = append(p.typList, t) + dup := !t.IsKind(types.TFORW) // type already imported // read underlying type t0 := p.typ() @@ -514,10 +515,19 @@ func (p *importer) typ() *types.Type { result := p.paramList() nointerface := p.bool() + mt := functypefield(recv[0], params, result) + addmethod(sym, mt, false, nointerface) + + if dup { + // An earlier import already declared this type and its methods. + // Discard the duplicate method declaration. + p.funcList = append(p.funcList, nil) + continue + } + n := newfuncname(methodname(sym, recv[0].Type)) - n.Type = functypefield(recv[0], params, result) + n.Type = mt checkwidth(n.Type) - addmethod(sym, n.Type, false, nointerface) p.funcList = append(p.funcList, n) importlist = append(importlist, n)