1
0
mirror of https://github.com/golang/go synced 2024-11-12 10:30:23 -07:00

[dev.ssa] cmd/compile: cache sparse sets in Config

Move the cached sparse sets to the Config.  I tested make.bash with
pre-allocating sets of size 150 and not caching very small sets, but the
difference between this implementation (no min size, no preallocation)
and a min size with preallocation was fairly negligible:

Number of sparse sets allocated:
Cached in Config w/none preallocated no min size    3684 *this CL*
Cached in Config w/three preallocated no min size   3370
Cached in Config w/three preallocated min size=150  3370
Cached in Config w/none preallocated min size=150  15947
Cached in Func,  w/no min                          96996 *previous code*

Change-Id: I7f9de8a7cae192648a7413bfb18a6690fad34375
Reviewed-on: https://go-review.googlesource.com/19152
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Todd Neal 2016-02-02 06:35:34 -05:00
parent 16b1fce921
commit 3297a4f5f3
2 changed files with 8 additions and 8 deletions

View File

@ -23,6 +23,8 @@ type Config struct {
// Storage for low-numbered values and blocks. // Storage for low-numbered values and blocks.
values [2000]Value values [2000]Value
blocks [200]Block blocks [200]Block
scrSparse []*sparseSet // scratch sparse sets to be re-used.
} }
type TypeSource interface { type TypeSource interface {

View File

@ -31,8 +31,6 @@ type Func struct {
freeValues *Value // free Values linked by argstorage[0]. All other fields except ID are 0/nil. freeValues *Value // free Values linked by argstorage[0]. All other fields except ID are 0/nil.
freeBlocks *Block // free Blocks linked by succstorage[0]. All other fields except ID are 0/nil. freeBlocks *Block // free Blocks linked by succstorage[0]. All other fields except ID are 0/nil.
scrSparse []*sparseSet // sparse sets to be re-used.
} }
// NumBlocks returns an integer larger than the id of any Block in the Func. // NumBlocks returns an integer larger than the id of any Block in the Func.
@ -47,9 +45,9 @@ func (f *Func) NumValues() int {
// newSparseSet returns a sparse set that can store at least up to n integers. // newSparseSet returns a sparse set that can store at least up to n integers.
func (f *Func) newSparseSet(n int) *sparseSet { func (f *Func) newSparseSet(n int) *sparseSet {
for i, scr := range f.scrSparse { for i, scr := range f.Config.scrSparse {
if scr != nil && scr.cap() >= n { if scr != nil && scr.cap() >= n {
f.scrSparse[i] = nil f.Config.scrSparse[i] = nil
scr.clear() scr.clear()
return scr return scr
} }
@ -57,15 +55,15 @@ func (f *Func) newSparseSet(n int) *sparseSet {
return newSparseSet(n) return newSparseSet(n)
} }
// retSparseSet returns a sparse set to the function's cache to be reused by f.newSparseSet. // retSparseSet returns a sparse set to the config's cache of sparse sets to be reused by f.newSparseSet.
func (f *Func) retSparseSet(ss *sparseSet) { func (f *Func) retSparseSet(ss *sparseSet) {
for i, scr := range f.scrSparse { for i, scr := range f.Config.scrSparse {
if scr == nil { if scr == nil {
f.scrSparse[i] = ss f.Config.scrSparse[i] = ss
return return
} }
} }
f.scrSparse = append(f.scrSparse, ss) f.Config.scrSparse = append(f.Config.scrSparse, ss)
} }
// newValue allocates a new Value with the given fields and places it at the end of b.Values. // newValue allocates a new Value with the given fields and places it at the end of b.Values.