From 0d176621d925915152b7b0b332e553b6f0d635e2 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 26 Oct 2016 22:05:20 -0700 Subject: [PATCH] cmd/compile: reuse sort helpers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit sort.Sort's argument always escapes. cse generates many calls to sort.Sort. Set up a single escaping variable and re-use it across loops. name old alloc/op new alloc/op delta Template 40.7MB ± 0% 40.2MB ± 0% -1.24% (p=0.000 n=15+15) Unicode 33.4MB ± 0% 33.3MB ± 0% -0.09% (p=0.000 n=15+15) GoTypes 121MB ± 0% 119MB ± 0% -1.48% (p=0.000 n=14+15) Compiler 474MB ± 0% 465MB ± 0% -1.94% (p=0.000 n=14+15) name old allocs/op new allocs/op delta Template 405k ± 0% 394k ± 0% -2.64% (p=0.000 n=15+15) Unicode 350k ± 0% 350k ± 0% -0.14% (p=0.000 n=14+15) GoTypes 1.21M ± 0% 1.18M ± 0% -3.07% (p=0.000 n=15+14) Compiler 4.37M ± 0% 4.18M ± 0% -4.39% (p=0.000 n=15+15) Change-Id: I68cf56dafa0f3ea778826eea19908bd761556154 Reviewed-on: https://go-review.googlesource.com/32220 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/cse.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/cse.go b/src/cmd/compile/internal/ssa/cse.go index 24f071bcfd..9410433325 100644 --- a/src/cmd/compile/internal/ssa/cse.go +++ b/src/cmd/compile/internal/ssa/cse.go @@ -83,6 +83,7 @@ func cse(f *Func) { // non-equivalent arguments. Repeat until we can't find any // more splits. var splitPoints []int + byArgClass := new(partitionByArgClass) // reuseable partitionByArgClass to reduce allocations for { changed := false @@ -92,7 +93,9 @@ func cse(f *Func) { e := partition[i] // Sort by eq class of arguments. - sort.Sort(partitionByArgClass{e, valueEqClass}) + byArgClass.a = e + byArgClass.eqClass = valueEqClass + sort.Sort(byArgClass) // Find split points. splitPoints = append(splitPoints[:0], 0) @@ -147,8 +150,11 @@ func cse(f *Func) { // Compute substitutions we would like to do. We substitute v for w // if v and w are in the same equivalence class and v dominates w. rewrite := make([]*Value, f.NumValues()) + byDom := new(partitionByDom) // reusable partitionByDom to reduce allocs for _, e := range partition { - sort.Sort(partitionByDom{e, sdom}) + byDom.a = e + byDom.sdom = sdom + sort.Sort(byDom) for i := 0; i < len(e)-1; i++ { // e is sorted by domorder, so a maximal dominant element is first in the slice v := e[i] -- 2.48.1