Skip to content

Commit 1b03568

Browse files
committed
cmd/compile: adjust PGO inlining default parameters
Adjust PGO inlining default parameters to 99% CDF threshold and 2000 budget. Benchmark results (mostly from Sweet) show that this set of parameters performs reasonably well, with a few percent speedup at the cost of a few percent binary size increase. Also rename the debug flags to start with "pgo", to make it clear that they are related to PGO. Change-Id: I0749249b1298d1dc55a28993c37b3185f9d7639d Reviewed-on: https://go-review.googlesource.com/c/go/+/449477 Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 5497300 commit 1b03568

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

src/cmd/compile/internal/base/debug.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@ var Debug DebugFlags
1616
// The -d option takes a comma-separated list of settings.
1717
// Each setting is name=value; for ints, name is short for name=1.
1818
type DebugFlags struct {
19-
Append int `help:"print information about append compilation"`
20-
Checkptr int `help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation" concurrent:"ok"`
21-
Closure int `help:"print information about closure compilation"`
22-
DclStack int `help:"run internal dclstack check"`
23-
Defer int `help:"print information about defer compilation"`
24-
DisableNil int `help:"disable nil checks" concurrent:"ok"`
25-
DumpPtrs int `help:"show Node pointers values in dump output"`
26-
DwarfInl int `help:"print information about DWARF inlined function creation"`
27-
Export int `help:"print export data"`
28-
Fmahash string `help:"hash value for use in debugging platform-dependent multiply-add use" concurrent:"ok"`
29-
GCAdjust int `help:"log adjustments to GOGC" concurrent:"ok"`
30-
GCProg int `help:"print dump of GC programs"`
31-
Gossahash string `help:"hash value for use in debugging the compiler"`
32-
InlFuncsWithClosures int `help:"allow functions with closures to be inlined" concurrent:"ok"`
33-
Libfuzzer int `help:"enable coverage instrumentation for libfuzzer"`
34-
LocationLists int `help:"print information about DWARF location list creation"`
35-
Nil int `help:"print information about nil checks"`
36-
NoOpenDefer int `help:"disable open-coded defers" concurrent:"ok"`
37-
NoRefName int `help:"do not include referenced symbol names in object file" concurrent:"ok"`
38-
PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"`
39-
Panic int `help:"show all compiler panics"`
40-
Reshape int `help:"print information about expression reshaping"`
41-
Shapify int `help:"print information about shaping recursive types"`
42-
Slice int `help:"print information about slice compilation"`
43-
SoftFloat int `help:"force compiler to emit soft-float code" concurrent:"ok"`
44-
SyncFrames int `help:"how many writer stack frames to include at sync points in unified export data"`
45-
TypeAssert int `help:"print information about type assertion inlining"`
46-
TypecheckInl int `help:"eager typechecking of inline function bodies" concurrent:"ok"`
47-
Unified int `help:"enable unified IR construction"`
48-
WB int `help:"print information about write barriers"`
49-
ABIWrap int `help:"print information about ABI wrapper generation"`
50-
MayMoreStack string `help:"call named function before all stack growth checks" concurrent:"ok"`
51-
InlineHotCallSiteCDFThreshold string `help:"cummulative threshold percentage for determining call sites as hot candidates for inlining" concurrent:"ok"`
52-
InlineHotBudget int `help:"inline budget for hot functions" concurrent:"ok"`
53-
PGOInline int `help:"debug profile-guided inlining"`
19+
Append int `help:"print information about append compilation"`
20+
Checkptr int `help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation" concurrent:"ok"`
21+
Closure int `help:"print information about closure compilation"`
22+
DclStack int `help:"run internal dclstack check"`
23+
Defer int `help:"print information about defer compilation"`
24+
DisableNil int `help:"disable nil checks" concurrent:"ok"`
25+
DumpPtrs int `help:"show Node pointers values in dump output"`
26+
DwarfInl int `help:"print information about DWARF inlined function creation"`
27+
Export int `help:"print export data"`
28+
Fmahash string `help:"hash value for use in debugging platform-dependent multiply-add use" concurrent:"ok"`
29+
GCAdjust int `help:"log adjustments to GOGC" concurrent:"ok"`
30+
GCProg int `help:"print dump of GC programs"`
31+
Gossahash string `help:"hash value for use in debugging the compiler"`
32+
InlFuncsWithClosures int `help:"allow functions with closures to be inlined" concurrent:"ok"`
33+
Libfuzzer int `help:"enable coverage instrumentation for libfuzzer"`
34+
LocationLists int `help:"print information about DWARF location list creation"`
35+
Nil int `help:"print information about nil checks"`
36+
NoOpenDefer int `help:"disable open-coded defers" concurrent:"ok"`
37+
NoRefName int `help:"do not include referenced symbol names in object file" concurrent:"ok"`
38+
PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"`
39+
Panic int `help:"show all compiler panics"`
40+
Reshape int `help:"print information about expression reshaping"`
41+
Shapify int `help:"print information about shaping recursive types"`
42+
Slice int `help:"print information about slice compilation"`
43+
SoftFloat int `help:"force compiler to emit soft-float code" concurrent:"ok"`
44+
SyncFrames int `help:"how many writer stack frames to include at sync points in unified export data"`
45+
TypeAssert int `help:"print information about type assertion inlining"`
46+
TypecheckInl int `help:"eager typechecking of inline function bodies" concurrent:"ok"`
47+
Unified int `help:"enable unified IR construction"`
48+
WB int `help:"print information about write barriers"`
49+
ABIWrap int `help:"print information about ABI wrapper generation"`
50+
MayMoreStack string `help:"call named function before all stack growth checks" concurrent:"ok"`
51+
PGOInlineCDFThreshold string `help:"cummulative threshold percentage for determining call sites as hot candidates for inlining" concurrent:"ok"`
52+
PGOInlineBudget int `help:"inline budget for hot functions" concurrent:"ok"`
53+
PGOInline int `help:"debug profile-guided inlining"`
5454

5555
ConcurrentOk bool // true if only concurrentOk flags seen
5656
}

src/cmd/compile/internal/inline/inl.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ var (
7676
// that is, for a threshold of X the hottest callsites that
7777
// make up the top X% of total edge weight will be
7878
// considered hot for inlining candidates.
79-
inlineCDFHotCallSiteThresholdPercent = float64(95)
79+
inlineCDFHotCallSiteThresholdPercent = float64(99)
8080

8181
// Budget increased due to hotness.
82-
inlineHotMaxBudget int32 = 160
82+
inlineHotMaxBudget int32 = 2000
8383
)
8484

8585
// pgoInlinePrologue records the hot callsites from ir-graph.
8686
func pgoInlinePrologue(p *pgo.Profile, decls []ir.Node) {
87-
if s, err := strconv.ParseFloat(base.Debug.InlineHotCallSiteCDFThreshold, 64); err == nil {
87+
if s, err := strconv.ParseFloat(base.Debug.PGOInlineCDFThreshold, 64); err == nil {
8888
inlineCDFHotCallSiteThresholdPercent = s
8989
}
9090
var hotCallsites []pgo.NodeMapKey
@@ -93,8 +93,8 @@ func pgoInlinePrologue(p *pgo.Profile, decls []ir.Node) {
9393
fmt.Printf("hot-callsite-thres-from-CDF=%v\n", inlineHotCallSiteThresholdPercent)
9494
}
9595

96-
if base.Debug.InlineHotBudget != 0 {
97-
inlineHotMaxBudget = int32(base.Debug.InlineHotBudget)
96+
if x := base.Debug.PGOInlineBudget; x != 0 {
97+
inlineHotMaxBudget = int32(x)
9898
}
9999

100100
// mark inlineable callees from hot edges

src/cmd/compile/internal/test/pgo_inl_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ go 1.19
6767
expectedNotInlinedList[fullName] = struct{}{}
6868
}
6969

70-
// go test -c -o /tmp/test.exe -cpuprofile inline_hot.pprof
70+
// Build the test with the profile. Use a smaller threshold to test.
71+
// TODO: maybe adjust the test to work with default threshold.
7172
pprof := filepath.Join(dir, "inline_hot.pprof")
72-
gcflag := fmt.Sprintf("-gcflags=-m -m -pgoprofile %s", pprof)
73+
gcflag := fmt.Sprintf("-gcflags=-m -m -pgoprofile=%s -d=pgoinlinebudget=160,pgoinlinecdfthreshold=90", pprof)
7374
out := filepath.Join(dir, "test.exe")
7475
cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), "test", "-c", "-o", out, gcflag, "."))
7576
cmd.Dir = dir

0 commit comments

Comments
 (0)