Description
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.
Activity
michaelwoerister commentedon Aug 11, 2022
@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.
Kobzol commentedon Aug 11, 2022
Ok, I will try to send a PR to fix this.
rustc
is invoked bycargo
once per crate, not once per source file, right? Otherwise the bottleneck might be a bit too much.michaelwoerister commentedon Aug 11, 2022
Yes, once per crate.
-Cprofile-use
and-Cprofile-sample-use
value by file hash, not file path #100413