From: Josh Bleecher Snyder Date: Thu, 27 Oct 2016 06:40:14 +0000 (-0700) Subject: cmd/compile: combine slice allocations in newblock X-Git-Tag: go1.8beta1~538 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=23d762c1298f6e3f0507debc9bfba83c66a8796e;p=gostls13.git cmd/compile: combine slice allocations in newblock name old allocs/op new allocs/op delta Template 394k ± 0% 391k ± 0% -0.80% (p=0.000 n=10+10) Unicode 350k ± 0% 349k ± 0% -0.27% (p=0.000 n=10+10) GoTypes 1.18M ± 0% 1.17M ± 0% -0.92% (p=0.000 n=10+10) Compiler 4.18M ± 0% 4.14M ± 0% -1.05% (p=0.000 n=10+10) Change-Id: I838a4e2110afe6496c535b9a0ec5aa882d63a707 Reviewed-on: https://go-review.googlesource.com/32223 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index dc2b09eee7..0936ee6248 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -114,8 +114,11 @@ func newblock(prog *obj.Prog) *BasicBlock { result.mark = UNVISITED result.first = prog result.last = prog - result.pred = make([]*BasicBlock, 0, 2) - result.succ = make([]*BasicBlock, 0, 2) + // We want two 0-len slices with capacity 2. + // Carve them out of a single allocation. + blocks := make([]*BasicBlock, 4) + result.pred = blocks[0:][:0:2] + result.succ = blocks[2:][:0:2] return result }