Open8

【Go】PGO(Profile-guided optimization)

KeigoIbarakiKeigoIbaraki

Release Note ベースの話(1.21)

Compiler

Profile-guide optimization (PGO), added as a preview in Go 1.20, is now ready for general use. PGO enables additional optimizations on code identified as hot by profiles of production workloads. As mentioned in the Go command section, PGO is enabled by default for binaries that contain a default.pgo profile in the main package directory. Performance improvements vary depending on application behavior, with most programs from a representative set of Go programs seeing between 2 and 7% improvement from enabling PGO. See the PGO user guide for detailed documentation.

PGO builds can now devirtualize some interface method calls, adding a concrete call to the most common callee. This enables further optimization, such as inlining the callee.

Go 1.21 improves build speed by up to 6%, largely thanks to building the compiler itself with PGO.

https://tip.golang.org/doc/go1.21#compiler

Go Command

The -pgo build flag now defaults to -pgo=auto, and the restriction of specifying a single main package on the command line is now removed. If a file named default.pgo is present in the main package’s directory, the go command will use it to enable profile-guided optimization for building the corresponding program.

The -C dir flag must now be the first flag on the command-line when used.

The new go test option -fullpath prints full path names in test log messages, rather than just base names.

The go test -c flag now supports writing test binaries for multiple packages, each to pkg.test where pkg is the package name. It is an error if more than one test package being compiled has a given package name.

The go test -o flag now accepts a directory argument, in which case test binaries are written to that directory instead of the current directory.

When using an external (C) linker with cgo enabled, the runtime/cgo package is now supplied to the Go linker as an additional dependency to ensure that the Go runtime is compatible with any additional libraries added by the C linker.

https://tip.golang.org/doc/go1.21#go-command

KeigoIbarakiKeigoIbaraki

Release Note ベースの話(1.22)

inlining の話も一気に載せてしまう

Compiler

Profile-guided Optimization (PGO) builds can now devirtualize a higher proportion of calls than previously possible. Most programs from a representative set of Go programs now see between 2 and 14% improvement at runtime from enabling PGO.

The compiler now interleaves devirtualization and inlining, so interface method calls are better optimized.

Go 1.22 also includes a preview of an enhanced implementation of the compiler’s inlining phase that uses heuristics to boost inlinability at call sites deemed “important” (for example, in loops) and discourage inlining at call sites deemed “unimportant” (for example, on panic paths). Building with GOEXPERIMENT=newinliner enables the new call-site heuristics; see issue #61502 for more info and to provide feedback.