cmd/compile: order functions by IR node count
Count nodes during the existing pre-walk traversal and use that
count instead of the number of top-level statements when ordering
functions for compilation.
compilebench Intel Alder Lake 12600k (P cores):
│ /home/jake/26jul/costmodel.master │ /home/jake/26jul/costmodel.new │
│ sec/op │ sec/op vs base │
Template 87.92m ± 1% 88.16m ± 1% ~ (p=0.341 n=20)
Unicode 61.10m ± 1% 61.17m ± 1% ~ (p=0.429 n=20)
GoTypes 544.1m ± 0% 542.9m ± 1% -0.23% (p=0.046 n=20)
Compiler 83.30m ± 1% 81.97m ± 1% -1.60% (p=0.000 n=20)
SSA 5.170 ± 0% 5.061 ± 0% -2.11% (p=0.000 n=20)
Flate 95.04m ± 0% 94.80m ± 0% ~ (p=0.192 n=20)
GoParser 96.25m ± 0% 84.29m ± 1% -12.43% (p=0.000 n=20)
Reflect 229.2m ± 0% 227.6m ± 1% -0.69% (p=0.000 n=20)
Tar 100.23m ± 1% 99.12m ± 0% -1.11% (p=0.000 n=20)
XML 114.7m ± 1% 113.3m ± 0% -1.29% (p=0.000 n=20)
LinkCompiler 286.8m ± 1% 285.6m ± 1% ~ (p=0.820 n=20)
ExternalLinkCompiler 760.9m ± 0% 760.8m ± 0% ~ (p=0.841 n=20)
LinkWithoutDebugCompiler 182.8m ± 1% 179.5m ± 1% -1.83% (p=0.000 n=20)
StdCmd 36.82 ± 0% 36.60 ± 0% -0.61% (p=0.001 n=20)
geomean 298.5m 293.6m -1.63%
│ /home/jake/26jul/costmodel.master │ /home/jake/26jul/costmodel.new │
│ user-sec/op │ user-sec/op vs base │
Template 225.9m ± 1% 225.2m ± 2% ~ (p=0.846 n=20)
Unicode 67.70m ± 4% 67.59m ± 4% ~ (p=0.841 n=20)
GoTypes 1.791 ± 1% 1.775 ± 1% -0.87% (p=0.038 n=20)
Compiler 164.4m ± 2% 163.8m ± 2% ~ (p=0.142 n=20)
SSA 17.56 ± 1% 17.63 ± 1% ~ (p=0.989 n=20)
Flate 269.2m ± 2% 270.1m ± 1% ~ (p=0.738 n=20)
GoParser 232.4m ± 2% 232.0m ± 2% ~ (p=0.779 n=20)
Reflect 644.1m ± 1% 642.5m ± 0% ~ (p=0.547 n=20)
Tar 267.3m ± 1% 261.6m ± 1% -2.13% (p=0.000 n=20)
XML 313.7m ± 1% 304.0m ± 1% -3.11% (p=0.000 n=20)
LinkCompiler 462.1m ± 1% 468.6m ± 1% +1.41% (p=0.013 n=20)
ExternalLinkCompiler 848.9m ± 1% 846.6m ± 1% ~ (p=0.779 n=20)
LinkWithoutDebugCompiler 213.1m ± 2% 213.3m ± 2% ~ (p=0.429 n=20)
geomean 438.7m 436.9m -0.43%
diff --git a/src/cmd/compile/internal/gc/compile.go b/src/cmd/compile/internal/gc/compile.go
index 3d8974e..e1867d8 100644
--- a/src/cmd/compile/internal/gc/compile.go
+++ b/src/cmd/compile/internal/gc/compile.go
@@ -148,7 +148,7 @@
// Since we remove from the end of the slice queue,
// that means shortest to longest.
slices.SortFunc(compilequeue, func(a, b *ir.Func) int {
- return cmp.Compare(len(a.Body), len(b.Body))
+ return cmp.Compare(a.NumPreWalkNodes, b.NumPreWalkNodes)
})
}
diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go
index e387927..c6675e2 100644
--- a/src/cmd/compile/internal/ir/func.go
+++ b/src/cmd/compile/internal/ir/func.go
@@ -55,6 +55,11 @@
// if you add or remove a field, don't forget to update sizeof_test.go
miniNode
+
+ // NumPreWalkNodes is the number of IR nodes before Walk.
+ // It is used as an estimate of backend compilation cost.
+ NumPreWalkNodes int32
+
Body Nodes
Nname *Name // ONAME node
diff --git a/src/cmd/compile/internal/ir/sizeof_test.go b/src/cmd/compile/internal/ir/sizeof_test.go
index b805155..047de93 100644
--- a/src/cmd/compile/internal/ir/sizeof_test.go
+++ b/src/cmd/compile/internal/ir/sizeof_test.go
@@ -20,7 +20,7 @@
_32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms
}{
- {Func{}, 184, 312},
+ {Func{}, 188, 312},
{Name{}, 96, 160},
{miniExpr{}, 32, 48},
{miniNode{}, 12, 12},
diff --git a/src/cmd/compile/internal/walk/walk.go b/src/cmd/compile/internal/walk/walk.go
index 68e8545..ac81661 100644
--- a/src/cmd/compile/internal/walk/walk.go
+++ b/src/cmd/compile/internal/walk/walk.go
@@ -471,7 +471,9 @@
ro.Init(fn)
sv := make(map[ir.Node]ir.Node)
scs := make(map[*ir.Name]*types.Type)
+ var numNodes int32
ir.Visit(fn, func(n ir.Node) {
+ numNodes++
switch n.Op() {
case ir.OCONVIFACE:
x := n.(*ir.ConvExpr).X
@@ -496,4 +498,5 @@
})
staticValues = sv
shapeConvSources = scs
+ fn.NumPreWalkNodes = numNodes
}
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
Ooh thanks! This looks good! I'll try running benchmarks on some other machines.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
There's not much of a difference on the amd64 GoBuild sweet benchmarks, but the c4 72 core builder does show a noticeable improvement.
There's not much of a difference on the amd64 GoBuild sweet benchmarks, but the c4 72 core builder does show a noticeable improvement.
Thanks for doing the benches, how much of a difference was it on the 72 core one?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |