Skip to content

PGO profile invalidation in -Cprofile-use #100397

@Kobzol

Description

@Kobzol
Member

Hi! While working on https://github.com/Kobzol/cargo-pgo, I noticed a peculiar thing about the invalidation of the PGO profile path.
When PGO is used for compiling, we specify the path to the PGO profile using -Cprofile-use=<path>. When <path> changes, it invalidates the compilation session, so the code is recompiled again (as it should be, if the profile changes).

However, if the path stays the same, but the contents of the profile file change, the code will not be recompiled. That can be a footgun, since users might try to gather profiles incrementally and then try to compile/benchmark using the new profiles, but if the profile path stays the same (if it's just overwritten each time), they might not notice that the code is not recompiled and they thus might get stale results.

Would it be feasible to check the hash/modification time of the profile file instead of just the file path, w.r.t. invalidating recompilation? Is there any prior art to this in some other Rust flags?

I think that hashing the file wouldn't be such a bottleneck (I think that it was done for sccache here), unless it would have to be done by every rustc invocation instead of just once per Cargo run? 🤔 I don't think that -Cprofile-use is that common that this would cause perf. problems, but it could resolve a potential footgun.

CC @michaelwoerister

Activity

michaelwoerister

michaelwoerister commented on Aug 11, 2022

@michaelwoerister
Member

@Kobzol, I agree with your assessment of the problem. I don't think we have prior art here. Source files, upstream crate, and external libraries are all handled in a different way.

The most correct way to do this would be to generate and compare a hash in each rustc invocation. Comparing time stamps would be acceptable too, I think. The hash/timestamp could then be fed into the hash we already generate for commandline arguments.

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-incr-compArea: Incremental compilation
C-bugCategory: This is a bug.
on Aug 11, 2022
Kobzol

Kobzol commented on Aug 11, 2022

@Kobzol
MemberAuthor

Ok, I will try to send a PR to fix this. rustc is invoked by cargo once per crate, not once per source file, right? Otherwise the bottleneck might be a bit too much.

michaelwoerister

michaelwoerister commented on Aug 11, 2022

@michaelwoerister
Member

Yes, once per crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @michaelwoerister@Kobzol

      Issue actions

        PGO profile invalidation in `-Cprofile-use` · Issue #100397 · rust-lang/rust