Commit 16e430e1 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: reduce slice growth in fuseBlockPlain

Instead of always appending to c.Values,
choose whichever slice is larger;
b.Values will be set to nil anyway.

Appending once instead of in a loop also
limits slice growth to once per function call
and is more efficient.

Reduces max rss for the program in #18602 by 6.5%,
and eliminates fuseBlockPlain from the alloc_space
pprof output. fuseBlockPlain previously accounted
for 16.74% of allocated memory.

Updates #18602.

Change-Id: I417b03722d011a59a679157da43dc91f4425210e
Reviewed-on: https://go-review.googlesource.com/35114
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 01c8719f
......@@ -121,7 +121,14 @@ func fuseBlockPlain(b *Block) bool {
// move all of b's values to c.
for _, v := range b.Values {
v.Block = c
c.Values = append(c.Values, v)
}
// Use whichever value slice is larger, in the hopes of avoiding growth.
// However, take care to avoid c.Values pointing to b.valstorage.
// See golang.org/issue/18602.
if cap(c.Values) >= cap(b.Values) || len(b.Values) <= len(b.valstorage) {
c.Values = append(c.Values, b.Values...)
} else {
c.Values = append(b.Values, c.Values...)
}
// replace b->c edge with preds(b) -> c
......
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