]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate more allocs in newblock
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 28 Oct 2016 02:53:50 +0000 (19:53 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 28 Oct 2016 03:13:35 +0000 (03:13 +0000)
name       old allocs/op    new allocs/op    delta
Template         389k ± 0%        386k ± 0%  -0.84%        (p=0.000 n=10+10)
Unicode          323k ± 0%        323k ± 0%  -0.25%        (p=0.000 n=10+10)
GoTypes         1.17M ± 0%       1.16M ± 0%  -0.93%        (p=0.000 n=10+10)
Compiler        4.13M ± 0%       4.09M ± 0%  -1.05%        (p=0.000 n=10+10)

Change-Id: I6c00850d07511c2e65761c7373fc3df738499105
Reviewed-on: https://go-review.googlesource.com/32235
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/plive.go

index 0936ee6248afbf391d85b3fc9227854fe4bfff32..5fa864568fd5186c4390b0f3b2ab4642d59a8847 100644 (file)
@@ -109,16 +109,22 @@ func newblock(prog *obj.Prog) *BasicBlock {
        if prog == nil {
                Fatalf("newblock: prog cannot be nil")
        }
-       result := new(BasicBlock)
+       // type block allows us to allocate a BasicBlock
+       // and its pred/succ slice together.
+       type block struct {
+               result BasicBlock
+               pred   [2]*BasicBlock
+               succ   [2]*BasicBlock
+       }
+       b := new(block)
+
+       result := &b.result
        result.rpo = -1
        result.mark = UNVISITED
        result.first = prog
        result.last = prog
-       // 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]
+       result.pred = b.pred[:0]
+       result.succ = b.succ[:0]
        return result
 }