From 23d762c1298f6e3f0507debc9bfba83c66a8796e Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 26 Oct 2016 23:40:14 -0700 Subject: [PATCH] cmd/compile: combine slice allocations in newblock MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/cmd/compile/internal/gc/plive.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 } -- 2.48.1