[go] cmd/compile: order functions by IR node count

4 views
Skip to first unread message

Jakub Ciolek (Gerrit)

unread,
Jul 20, 2026, 8:54:43 AM (6 days ago) Jul 20
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Jakub Ciolek has uploaded the change for review

Commit message

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%
Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a

Change diff

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
}

Change information

Files:
  • M src/cmd/compile/internal/gc/compile.go
  • M src/cmd/compile/internal/ir/func.go
  • M src/cmd/compile/internal/ir/sizeof_test.go
  • M src/cmd/compile/internal/walk/walk.go
Change size: S
Delta: 4 files changed, 10 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
Gerrit-Change-Number: 802361
Gerrit-PatchSet: 1
Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
unsatisfied_requirement
satisfied_requirement
open
diffy

Jakub Ciolek (Gerrit)

unread,
Jul 20, 2026, 8:55:39 AM (6 days ago) Jul 20
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Jakub Ciolek voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
Gerrit-Change-Number: 802361
Gerrit-PatchSet: 1
Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Reviewer: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Comment-Date: Mon, 20 Jul 2026 12:55:33 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Michael Matloob (Gerrit)

unread,
Jul 21, 2026, 2:23:38 PM (5 days ago) Jul 21
to Jakub Ciolek, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Jakub Ciolek

Michael Matloob voted and added 1 comment

Votes added by Michael Matloob

Code-Review+2

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Michael Matloob . resolved

Ooh thanks! This looks good! I'll try running benchmarks on some other machines.

Open in Gerrit

Related details

Attention is currently required from:
  • Jakub Ciolek
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
Gerrit-Change-Number: 802361
Gerrit-PatchSet: 1
Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Reviewer: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Comment-Date: Tue, 21 Jul 2026 18:23:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Carlos Amedee (Gerrit)

unread,
Jul 21, 2026, 5:29:22 PM (5 days ago) Jul 21
to Jakub Ciolek, goph...@pubsubhelper.golang.org, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Jakub Ciolek

Carlos Amedee voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Jakub Ciolek
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
Gerrit-Change-Number: 802361
Gerrit-PatchSet: 1
Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
Gerrit-Reviewer: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Jakub Ciolek <ja...@ciolek.dev>
Gerrit-Comment-Date: Tue, 21 Jul 2026 21:29:17 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Matloob (Gerrit)

unread,
Jul 21, 2026, 10:39:43 PM (5 days ago) Jul 21
to Jakub Ciolek, goph...@pubsubhelper.golang.org, Carlos Amedee, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Jakub Ciolek

Michael Matloob voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Jakub Ciolek
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
    Gerrit-Change-Number: 802361
    Gerrit-PatchSet: 1
    Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
    Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
    Gerrit-Reviewer: Jakub Ciolek <ja...@ciolek.dev>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@google.com>
    Gerrit-Comment-Date: Wed, 22 Jul 2026 02:39:37 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Michael Matloob (Gerrit)

    unread,
    Jul 21, 2026, 10:48:10 PM (5 days ago) Jul 21
    to Jakub Ciolek, goph...@pubsubhelper.golang.org, Michael Matloob, Carlos Amedee, golang...@luci-project-accounts.iam.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Jakub Ciolek

    Michael Matloob added 1 comment

    Patchset-level comments
    Michael Matloob . resolved

    There's not much of a difference on the amd64 GoBuild sweet benchmarks, but the c4 72 core builder does show a noticeable improvement.

    Gerrit-Comment-Date: Wed, 22 Jul 2026 02:48:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    open
    diffy

    Jakub Ciolek (Gerrit)

    unread,
    Jul 22, 2026, 3:51:20 AM (4 days ago) Jul 22
    to goph...@pubsubhelper.golang.org, Michael Matloob, Carlos Amedee, Michael Matloob, golang...@luci-project-accounts.iam.gserviceaccount.com, Gopher Robot, golang-co...@googlegroups.com

    Jakub Ciolek added 1 comment

    Patchset-level comments
    Michael Matloob . resolved

    There's not much of a difference on the amd64 GoBuild sweet benchmarks, but the c4 72 core builder does show a noticeable improvement.

    Jakub Ciolek

    Thanks for doing the benches, how much of a difference was it on the 72 core one?

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I0389d056d5759117b768881f8ac1697f6cab366a
    Gerrit-Change-Number: 802361
    Gerrit-PatchSet: 1
    Gerrit-Owner: Jakub Ciolek <ja...@ciolek.dev>
    Gerrit-Reviewer: Carlos Amedee <car...@golang.org>
    Gerrit-Reviewer: Jakub Ciolek <ja...@ciolek.dev>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 22 Jul 2026 07:51:12 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Michael Matloob <mat...@golang.org>
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages