Commit f388b585 authored by Keith Randall's avatar Keith Randall

cmd/compile: reuseable cache of Prog structs

Reuseable cache of Prog entries.

Improves compiler speed by ~10%.

Update #13646

Change-Id: I01bd8606540d989ea8b8ba5131d1275ba380d976
Reviewed-on: https://go-review.googlesource.com/19868Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 45c2e38b
...@@ -618,6 +618,10 @@ type Link struct { ...@@ -618,6 +618,10 @@ type Link struct {
Data *LSym Data *LSym
Etext *LSym Etext *LSym
Edata *LSym Edata *LSym
// Cache of Progs
allocIdx int
progs [10000]Prog
} }
func (ctxt *Link) Diag(format string, args ...interface{}) { func (ctxt *Link) Diag(format string, args ...interface{}) {
......
...@@ -318,6 +318,7 @@ func Flushplist(ctxt *Link) { ...@@ -318,6 +318,7 @@ func Flushplist(ctxt *Link) {
ctxt.Plist = nil ctxt.Plist = nil
ctxt.Plast = nil ctxt.Plast = nil
ctxt.Curp = nil ctxt.Curp = nil
ctxt.freeProgs()
} }
func Writeobjfile(ctxt *Link, b *Biobuf) { func Writeobjfile(ctxt *Link, b *Biobuf) {
......
...@@ -325,10 +325,23 @@ func (p *Prog) String() string { ...@@ -325,10 +325,23 @@ func (p *Prog) String() string {
} }
func (ctxt *Link) NewProg() *Prog { 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 p.Ctxt = ctxt
return p 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 { func (ctxt *Link) Line(n int) string {
return ctxt.LineHist.LineString(n) return ctxt.LineHist.LineString(n)
......
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