-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for stabilizing Profile-Guided Optimization support #59913
Comments
Thanks for opening this up @michaelwoerister! One thing I might requests as well is a solid idea of how PGO could be integrated into a Cargo subcommand. I don't think we should add support to Cargo itself immediately, nor do I think a proof-of-concept is required to actually exist, but rather I think we should make sure that there's a solid idea of how this could be used by general folks. I suspect that such a command may not actually be used by codebases like Firefox, but for general optimization and usage I think it would be pretty valuable to have a solid "PGO in Rust story" in at least an MVP state which doesn't require tons of voodoo and working around various aspects of the build |
Why restricted -- shouldn't we welcome anyone to implement the other platforms? But it's understandable if it's only supported on tier 1 at first. |
Yeah, that's what I meant really: Stabilization would only entail support for tier 1 platforms. If other platforms work too that would be fine of course |
Yes, that's a good idea. What form would you expect this to take exactly? |
Heh well I've never actually done PGO myself, but knowing at least the basics of it in the very end it'd be cool to have something like:
where In the meantime though I'd be fine with:
which maybe runs the test suite by default? Something like |
That sounds like it should be straightforward to implement. The only complication I see is that the # Compile with instrumentation
rustc -Cprofile-generate=target/pgo src/main.rs
# Run the instrumented binary
target/release/proggy
# Run llvm-profdata to bring profiling data into usable state
llvm-profdata merge -output=target/pgo/proggy.profdata target/pgo
# Run the compiler again
rustc -Cprofile-use=target/pgo/proggy.profdata src/main.rs |
Indeed yeah I suspect it's straightforward :) I just want to make sure that the default use case isn't "oh be sure to install the compiler from source because we don't provide you everything" and shipping llvm-profdata with the llvm-tools component seems reasonable. (or maybe even renaming that to be rustc-specific rather than LLVM specific). The other thing I'd want to make sure is that it works reasonable well for dependencies as well, where if you have rlib dependencies you don't have anything special to do it "just works" or works somehow. (also FWIW I haven't used PGO before, this may already be the case!) |
Yes, that should already work if dependencies are built with instrumentation too (i.e. |
Is it possible to generate a pgo optimized rustc using |
Stabilize support for Profile-guided Optimization This PR makes profile-guided optimization available via the `-C profile-generate` / `-C profile-use` pair of commandline flags and adds end-user documentation for the feature to the [rustc book](https://doc.rust-lang.org/rustc/). The PR thus ticks the last two remaining checkboxes of the [stabilization tracking issue](#59913). From the tracking issue: > Profile-guided optimization (PGO) is a common optimization technique for ahead-of-time compilers. It works by collecting data about a program's typical execution (e.g. probability of branches taken, typical runtime values of variables, etc) and then uses this information during program optimization for things like inlining decisions, machine code layout, or indirect call promotion. If you are curious about how this can be used, there is a rendered version of the documentation this PR adds available [here]( https://github.com/michaelwoerister/rust/blob/stabilize-pgo/src/doc/rustc/src/profile-guided-optimization.md). r? @alexcrichton cc @rust-lang/compiler
@gnzlbg |
PGO has been stabilized in #61268 🎉 |
Profile-guided optimization (PGO) is a common optimization technique for ahead-of-time compilers. It works by collecting data about a programs typical execution (e.g. probability of branches taken, typical runtime values of variables, etc) and then uses this information during program optimization for things like inlining decisions, machine code layout, or indirect call promotion.
LLVM supports different forms of PGO, the most effective of which relies on generating instrumented binaries that collect the profiling information. The Rust compiler has had experimental support for this via the
-Z pgo-gen
and-Z pgo-use
flags for a while. This issue tracks the progress of making this functionality available in stable Rust.Steps:
run-make
test that makes sure thatinline
andcold
attributes are added to LLVM IR by LLVM's PGO passes. ( PGO: Add a run-make test that makes sure that PGO profiling data is used by the compiler during optimizations. #60262)codegen
test making sure that instrumentation is generated as expected. (Add codegen test for PGO instrumentation. #60038)run-make
test that makes sure PGO works in a mixed Rust/C++ codebase using ThinLTO done vialld
. (PGO - Add a smoketest for combining PGO with cross-language LTO. #61036)rustc
already behaves like Clang here: Pre-inlining is enabled except for-Copt-level=s
and-Copt-level=z
.-Z pgo-gen
commandline option. #59874)-C profile-generate
and-C profile-use
flags (mirroring the corresponding Clang flags).Non-Goals:
Further Information:
cc @rust-lang/core @rust-lang/compiler
The text was updated successfully, but these errors were encountered: