]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: reuseable cache of Prog structs
authorKeith Randall <khr@golang.org>
Wed, 24 Feb 2016 17:53:27 +0000 (09:53 -0800)
committerKeith Randall <khr@golang.org>
Wed, 24 Feb 2016 18:52:28 +0000 (18:52 +0000)
Reuseable cache of Prog entries.

Improves compiler speed by ~10%.

Update #13646

Change-Id: I01bd8606540d989ea8b8ba5131d1275ba380d976
Reviewed-on: https://go-review.googlesource.com/19868
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/util.go

index 0fe3275a8ebad674b926bb00e2164a40ea78c7f8..c63c8e3c56611caa00417da39e72a56224cca1c5 100644 (file)
@@ -618,6 +618,10 @@ type Link struct {
        Data  *LSym
        Etext *LSym
        Edata *LSym
+
+       // Cache of Progs
+       allocIdx int
+       progs    [10000]Prog
 }
 
 func (ctxt *Link) Diag(format string, args ...interface{}) {
index 3dc5152f544aabbe2e267bf6132652b19ff76f86..2d5c82376b4f0a70967b891af20efa84adca10a0 100644 (file)
@@ -318,6 +318,7 @@ func Flushplist(ctxt *Link) {
        ctxt.Plist = nil
        ctxt.Plast = nil
        ctxt.Curp = nil
+       ctxt.freeProgs()
 }
 
 func Writeobjfile(ctxt *Link, b *Biobuf) {
index 5103299526a10b5c3086a9016adf1c0659e20a77..12b048d8e14efa1d19fba1f17f897466f73e7c30 100644 (file)
@@ -325,10 +325,23 @@ func (p *Prog) String() string {
 }
 
 func (ctxt *Link) NewProg() *Prog {
-       p := new(Prog) // should be the only call to this; all others should use ctxt.NewProg
+       var p *Prog
+       if i := ctxt.allocIdx; i < len(ctxt.progs) {
+               p = &ctxt.progs[i]
+               ctxt.allocIdx = i + 1
+       } else {
+               p = new(Prog) // should be the only call to this; all others should use ctxt.NewProg
+       }
        p.Ctxt = ctxt
        return p
 }
+func (ctxt *Link) freeProgs() {
+       s := ctxt.progs[:ctxt.allocIdx]
+       for i := range s {
+               s[i] = Prog{}
+       }
+       ctxt.allocIdx = 0
+}
 
 func (ctxt *Link) Line(n int) string {
        return ctxt.LineHist.LineString(n)