rust-lang / rust-lang/rust

Add Temporal PGO support

Open
#157,806 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi!

It's an issue about adding support for another PGO kind, in addition to already supported in Rustc Instrumentation PGO (-Cprofile-generate/-Cprofile-use) and Sample-based PGO (-Zprofile-sample-use).

Temporal PGO is a special PGO kind that aims to improve application startup times instead of just raw performance. From internal implementation perspective it's a form of Instrumentation PGO with some additions. For more details and nuances please read the references below. Temporal PGO is already implemented in LLVM (already available with used by Rustc LLVM version) and Clang. From my findings, this feature is mostly used (and developed) by Meta engineers.

In this issue, at very first I want to raise an attention of existence this PGO kind in the world and its usefulness for real-world apps. Improving startup times is important for certain applications types (e.g. Rust-based mobile apps).

I've checked the Clang's implementation for -ftemporal-profile flag, and seems like we already can use this functionality via passing LLVM flags directly (from the Clang implementation):

CmdArgs.push_back("-mllvm");
CmdArgs.push_back("--pgo-temporal-instrumentation");

However, I haven't tested it yet a lot locally with Rustc.

My proposals:

  • At very least, document Temporal PGO somehow in Rustc PGO guide. Without that, it's almost impossible to find any kind of information about Temporal PGO usage with Rustc. For a regular person isn't clear, how Clang and LLVM docs are suitable for Rustc (e.g. with Clang it's not true since Clang has a dedicated frontend flag).
  • Discuss a need for Temporal PGO frontend flag (like Clang has). It's up to discussion since having a dedicated frontend flag just to pass a corresponding LLVM flag for such a niche (at least for now) feature can be overkill. On another hand, it makes UX a bit better + allows us to track on frontend side some interdependencies with other flags like -Cprofile-generate (according to the PR, Temporal PGO must be enabled with -Cprofile-generate) - we can think about doing it in a bit different way, and with potential -Ztemporal-profiling we can implicitly enable -Cprofile-generate. Or do in any other way. Anyway, adding an unstable flag could be a good start option since it's a non-binding addition to Rustc, and can be easily removed later.

Some helpful references about Temporal PGO:

  • Original RFC
  • LLVM DevMtg slides about Temporal PGO
  • LLVM PR for Temporal PGO
  • Clang -ftemporal-profile flag docs
  • Clang PR with adding -ftemporal-profile switch
  • Some context regarding deprecating other flags in favor of -ftemporal-profile: link

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 with Rustc's PGO guide and the existing -Cprofile-generate, -Cprofile-use, and -Zprofile-sample-use options, then compare them with the linked LLVM and Clang Temporal PGO references. The issue is complete only after maintainers decide whether documentation, a frontend flag, or both are in scope and the chosen behavior is validated.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.