rust-lang / rust-lang/rust

Introducing Profi into Rustc for better Sample PGO quality

Open
#156,898 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-PGO C-discussion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Hi!

Profi is an algorithm for improving Sample PGO profile quality by clever heuristics (more details read in the Reference in "Profi implementation". This functionality is already implemented in LLVM and integrated into Clang's PGO pipeline. Rust is lacking such of functionality for now.

Clang has -fsample-profile-use-profi flag. Clang already enabled using Profi default for Sample PGO use case 1 year.

At the moment, Profi can still be used with Rust by passing an additional LLVM flag: -Cllvm-args=-sample-profile-use-profi but I haven't tested it with Rustc yet.

Open questions:

  • Do we want to introduce an alternative to -fsample-profile-use-profi/-fno-sample-profile-use-profi into the Rustc compiler?
  • Do we want to enable Profi for Sample PGO by default? If yes, do we need to introduce flags to disable this behavior explicitly (see previous point). In this case, we can provide better Sample PGO experience for an average user - they don't need to know about an additional hidden LLVM argument that improves Sample PGO quality. At the moment, I have a draft commit about enabling it by default in my Rust fork: commit. We can partially mitigate it by adding such flags as a part of cargo-pgo but it's another discussion topic (especially since cargo-pgo doesn't support Sample PGO flow).
  • Do we need more evidence about Profi efficiency from practice? It's kinda difficult to find any evidency even for Clang. But in theory, Profi is a good idea.

Some references:

  • Profi implementation commits in LLVM: one, two, three
  • Adding -fsample-profile-use-profi flag into Clang: commit
  • Enabling using Profi by default in Clang: PR
  • Adding -fno-sample-profile-use-profi flag: PR
  • Some benchmarks about Profi efficiency: ChromeOS results, more results

Kindly pinging @ojeda since that functionality could be interesting for their use case too (even if seems like Google uses another approach internally). Maybe this approach with flow-sensitive discriminators should be pushed instead? Especially since exactly this approach is used in Rust-for-Linux.

Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing rustc's Sample PGO handling and the existing -Cllvm-args=-sample-profile-use-profi entry point, then compare it with Clang's -fsample-profile-use-profi and the linked LLVM changes. The draft commit and benchmark references provide context; done requires a decided Rust interface or default behavior, evidence requirements, and corresponding implementation and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.