From 5dbc67a99a99011fce1c1b7c983d2aa35247b950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sun, 21 Jan 2018 12:53:53 +0100 Subject: [PATCH] cmd/compile: avoid appends and allocate full slice length in copyRet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit passes toolstash -cmp compilebench allocs: name old allocs/op new allocs/op delta Template 385k ± 0% 385k ± 0% -0.00% (p=0.017 n=19+20) Unicode 342k ± 0% 342k ± 0% ~ (p=0.867 n=20+20) GoTypes 1.15M ± 0% 1.15M ± 0% -0.00% (p=0.008 n=20+20) SSA 12.1M ± 0% 12.1M ± 0% ~ (p=0.141 n=20+19) Flate 234k ± 0% 234k ± 0% ~ (p=0.125 n=20+19) GoParser 315k ± 0% 315k ± 0% ~ (p=0.104 n=20+20) Reflect 972k ± 0% 972k ± 0% -0.00% (p=0.000 n=17+20) Tar 391k ± 0% 391k ± 0% -0.01% (p=0.000 n=19+20) XML 404k ± 0% 403k ± 0% -0.01% (p=0.000 n=20+19) Change-Id: Ie24f7fae7b6b85422ec1ff0240f08f0a34064d72 Reviewed-on: https://go-review.googlesource.com/c/144038 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/order.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go index 3d0fa6ceb2..da2b3343a1 100644 --- a/src/cmd/compile/internal/gc/order.go +++ b/src/cmd/compile/internal/gc/order.go @@ -406,11 +406,13 @@ func (o *Order) copyRet(n *Node) []*Node { Fatalf("copyret %v %d", n.Type, n.Left.Type.NumResults()) } - var l1, l2 []*Node - for _, f := range n.Type.Fields().Slice() { - tmp := temp(f.Type) - l1 = append(l1, tmp) - l2 = append(l2, tmp) + slice := n.Type.Fields().Slice() + l1 := make([]*Node, len(slice)) + l2 := make([]*Node, len(slice)) + for i, t := range slice { + tmp := temp(t.Type) + l1[i] = tmp + l2[i] = tmp } as := nod(OAS2, nil, nil)