]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: reduce slice growth in fuseBlockPlain
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 11 Jan 2017 21:58:20 +0000 (13:58 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Feb 2017 18:50:54 +0000 (18:50 +0000)
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: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/fuse.go

index d5940da4396983e0e2ba8779ff0ec99dc377f41d..94a96120fa05bd8015a7164ff22f778f932fd43c 100644 (file)
@@ -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