-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pgo support for go 1.20 #3641
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An idea for testing: We could build the sample application twice in a go_bazel_test
, once with and once without pgo, and compare that the results differ.
1620a17
to
6d000ad
Compare
6d000ad
to
b1786e1
Compare
Co-authored-by: Fabian Meumertzheim <[email protected]>
This is fantastic. Do you know whether |
@sluongng Yes, the pgoprofile flag is applied when building the standard library. See changes in |
What type of PR is this?
Feature
What does this PR do? Why is it needed?
This PR add support for profile guided optimization for the go compiler.
The design is that we add a new label flag in go/config/BUILD.bazel which is used to set the a files target which would provide the first file to the compiler via
-pgoprofile
when compiling the standard library, all dependencies, and the go_binary target itself. This is achieved in a similar manner as other go.mode settings.The flag
-pgoprofile
only supports a single file and therefore this implementation only uses the first file provided by the target in//go/config:pgoprofile
. If more than one file is provided, then an error is raised at build evaluation time. However, this functionality could be extended to allow multiple files which are merged withgo tool pprof -proto a.pprof b.pprof > merged.pprof
. See the relevant pgo doc section for "Merging Profiles".Which issues(s) does this PR fix?
Fixes #3637
Other notes for review
I am not sure how to add unit tests for this. For reviewers, you can buildA diff test is added with guidance from @fmeum. You may also observe that other targets do not apply any pgoprofile flag unless provided with pgoprofile in the go_binary attributes or with//tests/core/go_binary:pgo
with the-s
flag and see that theGoStdlib
andGoCompilePkg
steps are completed with a-pgoprofile
flag with the appropriate pprof file.--@io_bazel_rules_go//go/config:pgoprofile=//path/to/some/file:target
.Example subcommands output of
bazel build //tests/core/go_binary:pgo -s
Observe
-pgoprofile tests/core/go_binary/pgo.pprof
on StdLib and GoCompilePkg steps.Thank you to @fmeum for your guidance on the implementation. This would not have been possible without your help.