Commit 4ae31dc8 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: re-use regalloc's []valState

Updates #27739: reduces package ssa's allocated space by 3.77%.

maxrss is harder to measure, but using best-of-three-runs
as reported by /usr/bin/time -l, I see ~2% reduction in maxrss.

We still have a long way to go, though; the new maxrss is still 1.1gb.

name        old alloc/op      new alloc/op      delta
Template         38.8MB ± 0%       37.7MB ± 0%  -2.77%  (p=0.008 n=5+5)
Unicode          28.2MB ± 0%       28.1MB ± 0%  -0.20%  (p=0.008 n=5+5)
GoTypes           131MB ± 0%        127MB ± 0%  -2.94%  (p=0.008 n=5+5)
Compiler          606MB ± 0%        587MB ± 0%  -3.21%  (p=0.008 n=5+5)
SSA              2.14GB ± 0%       2.06GB ± 0%  -3.77%  (p=0.008 n=5+5)
Flate            24.0MB ± 0%       23.3MB ± 0%  -3.00%  (p=0.008 n=5+5)
GoParser         28.8MB ± 0%       28.1MB ± 0%  -2.61%  (p=0.008 n=5+5)
Reflect          83.8MB ± 0%       81.5MB ± 0%  -2.71%  (p=0.008 n=5+5)
Tar              36.4MB ± 0%       35.4MB ± 0%  -2.73%  (p=0.008 n=5+5)
XML              47.9MB ± 0%       46.7MB ± 0%  -2.49%  (p=0.008 n=5+5)
[Geo mean]       84.6MB            82.4MB       -2.65%

name        old allocs/op     new allocs/op     delta
Template           379k ± 0%         379k ± 0%  -0.05%  (p=0.008 n=5+5)
Unicode            340k ± 0%         340k ± 0%    ~     (p=0.151 n=5+5)
GoTypes           1.36M ± 0%        1.36M ± 0%  -0.06%  (p=0.008 n=5+5)
Compiler          5.49M ± 0%        5.48M ± 0%  -0.03%  (p=0.008 n=5+5)
SSA               17.5M ± 0%        17.5M ± 0%  -0.03%  (p=0.008 n=5+5)
Flate              235k ± 0%         235k ± 0%  -0.04%  (p=0.008 n=5+5)
GoParser           302k ± 0%         302k ± 0%  -0.04%  (p=0.008 n=5+5)
Reflect            976k ± 0%         975k ± 0%  -0.10%  (p=0.008 n=5+5)
Tar                352k ± 0%         352k ± 0%  -0.06%  (p=0.008 n=5+5)
XML                436k ± 0%         436k ± 0%  -0.03%  (p=0.008 n=5+5)
[Geo mean]         842k              841k       -0.04%

Change-Id: I0ab6631b5a0bb6303c291dcb0367b586a4e584fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/176221
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 40657c28
......@@ -32,6 +32,8 @@ type Cache struct {
live []bool
q []*Value
}
// Reusable regalloc state.
regallocValues []valState
ValueToProgAfter []*obj.Prog
debugState debugState
......@@ -56,6 +58,12 @@ func (c *Cache) Reset() {
xl[i] = nil
}
// regalloc sets the length of c.regallocValues to whatever it may use,
// so clear according to length.
for i := range c.regallocValues {
c.regallocValues[i] = valState{}
}
// liveOrderStmts gets used multiple times during compilation of a function.
// We don't know where the high water mark was, so reslice to cap and search.
c.deadcode.liveOrderStmts = c.deadcode.liveOrderStmts[:cap(c.deadcode.liveOrderStmts)]
......
......@@ -651,8 +651,14 @@ func (s *regAllocState) init(f *Func) {
}
s.regs = make([]regState, s.numRegs)
s.values = make([]valState, f.NumValues())
s.orig = make([]*Value, f.NumValues())
nv := f.NumValues()
if cap(s.f.Cache.regallocValues) >= nv {
s.f.Cache.regallocValues = s.f.Cache.regallocValues[:nv]
} else {
s.f.Cache.regallocValues = make([]valState, nv)
}
s.values = s.f.Cache.regallocValues
s.orig = make([]*Value, nv)
s.copies = make(map[*Value]bool)
for _, b := range s.visitOrder {
for _, v := range b.Values {
......
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