We propose adding support for profile-guided optimization (PGO) to the Go gc toolchain. PGO will enable the toolchain to perform application- and workload-specific optimizations based on run-time information. Unlike many compiler optimizations, PGO requires user involvement to collect profiles and feed them back into the build process. Hence, we propose a design that centers user experience and ease of deployment and fits naturally into the broader Go build ecosystem.
Detailed design can be found here.
In summary, we propose
- The
go command will search for a profile named default.pgo in the source directory of the main package and, if present, will supply it to the compiler for all packages in the transitive dependencies of the main package. We will also add a -pgo=<path> command line flag to go build that specifies a profile location to use for a PGO build, specifically,
-pgo=<path> will select the profile at path,
-pgo=auto will select the profile stored in the source directory of the main package (the behavior mentioned above)
-pgo=off will turn off PGO entirely
- For Go 1.20, it will be default to
off. In a future release we plan to make it default to auto.
- The content of the profile will be considered an input to the build, and will be incorporated into the build cache key calculation and
BuildInfo.
- The compiler will support reading pprof profiles passed in from the
go command, and modify its optimization heuristics to use this profile information. Initially we plan to add PGO-based inlining. More optimizations may be added in the future.
- We will initially support pprof CPU profiles, which can be collected through usual means, such as the the
runtime/pprof or net/http/pprof packages.
Input welcome. Beyond input on the general approach, we're particularly looking for input on whether PGO should be default enabled in 1.20, and flag and file naming conventions.
If accepted, we plan to implement a preview of PGO in Go 1.20.
Raj Barik and Jin Lin plan to contribute their work on the compiler implementation (initial prototype in CL 429863, but not yet following proposed API).
See also previous discussions at #28262. Filing a new issue to make it clearer what we are proposing.
Thanks.
cc @aclements @prattmic @rajbarik
We propose adding support for profile-guided optimization (PGO) to the Go gc toolchain. PGO will enable the toolchain to perform application- and workload-specific optimizations based on run-time information. Unlike many compiler optimizations, PGO requires user involvement to collect profiles and feed them back into the build process. Hence, we propose a design that centers user experience and ease of deployment and fits naturally into the broader Go build ecosystem.
Detailed design can be found here.
In summary, we propose
gocommand will search for a profile nameddefault.pgoin the source directory of the main package and, if present, will supply it to the compiler for all packages in the transitive dependencies of the main package. We will also add a-pgo=<path>command line flag togo buildthat specifies a profile location to use for a PGO build, specifically,-pgo=<path>will select the profile atpath,-pgo=autowill select the profile stored in the source directory of the main package (the behavior mentioned above)-pgo=offwill turn off PGO entirelyoff. In a future release we plan to make it default toauto.BuildInfo.gocommand, and modify its optimization heuristics to use this profile information. Initially we plan to add PGO-based inlining. More optimizations may be added in the future.runtime/pprofornet/http/pprofpackages.Input welcome. Beyond input on the general approach, we're particularly looking for input on whether PGO should be default enabled in 1.20, and flag and file naming conventions.
If accepted, we plan to implement a preview of PGO in Go 1.20.
Raj Barik and Jin Lin plan to contribute their work on the compiler implementation (initial prototype in CL 429863, but not yet following proposed API).
See also previous discussions at #28262. Filing a new issue to make it clearer what we are proposing.
Thanks.
cc @aclements @prattmic @rajbarik