Skip to content

Commit 0aa14fc

Browse files
committed
cmd/go: enable -pgo=auto by default
Updates #58099. Updates #55022. Change-Id: I32eacdf9f008d16566e0b30230ecc25d110a9811 Reviewed-on: https://go-review.googlesource.com/c/go/+/474236 Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 3d28e0e commit 0aa14fc

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/cmd/go/alldocs.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/load/pkg.go

-2
Original file line numberDiff line numberDiff line change
@@ -2939,8 +2939,6 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
29392939
// In -pgo=auto mode, it finds the default PGO profile.
29402940
func setPGOProfilePath(pkgs []*Package) {
29412941
switch cfg.BuildPGO {
2942-
case "":
2943-
fallthrough // default to "off"
29442942
case "off":
29452943
return
29462944

src/cmd/go/internal/work/build.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ and test commands:
163163
build, the go command selects a file named "default.pgo" in the package's
164164
directory if that file exists, and applies it to the (transitive)
165165
dependencies of the main package (other packages are not affected).
166-
Special name "off" turns off PGO.
166+
Special name "off" turns off PGO. The default is "auto".
167167
-pkgdir dir
168168
install and load all packages from dir instead of the usual locations.
169169
For example, when building with a non-standard configuration,
@@ -318,7 +318,7 @@ func AddBuildFlags(cmd *base.Command, mask BuildFlagMask) {
318318
cmd.Flag.StringVar(&cfg.BuildContext.InstallSuffix, "installsuffix", "", "")
319319
cmd.Flag.Var(&load.BuildLdflags, "ldflags", "")
320320
cmd.Flag.BoolVar(&cfg.BuildLinkshared, "linkshared", false, "")
321-
cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "", "")
321+
cmd.Flag.StringVar(&cfg.BuildPGO, "pgo", "auto", "")
322322
cmd.Flag.StringVar(&cfg.BuildPkgdir, "pkgdir", "", "")
323323
cmd.Flag.BoolVar(&cfg.BuildRace, "race", false, "")
324324
cmd.Flag.BoolVar(&cfg.BuildMSan, "msan", false, "")

src/cmd/go/testdata/script/build_pgo_auto.txt

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ go list -test -pgo=auto ./a/a1
3434

3535
go list -deps -pgo=auto ./a/a1
3636

37+
# -pgo=auto is the default. Commands without explicit -pgo=auto
38+
# should work as -pgo=auto.
39+
go build -n ./a/a1
40+
stderr 'compile.*-pgoprofile=.*default\.pgo.*a1.go'
41+
stderr 'compile.*-p test/dep.*-pgoprofile=.*default\.pgo'
42+
43+
go build -n -o nopgo.exe ./nopgo
44+
stderr 'compile.*nopgo.go'
45+
! stderr '-pgoprofile'
46+
47+
# -pgo=off should turn off PGO.
48+
go build -n -pgo=off ./a/a1
49+
stderr 'compile.*a1.go'
50+
! stderr '-pgoprofile'
51+
3752
-- go.mod --
3853
module test
3954
go 1.20

0 commit comments

Comments
 (0)