Skip to content
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

PGO as part of cargo install? #39

Closed
SUPERCILEX opened this issue Sep 3, 2023 · 4 comments
Closed

PGO as part of cargo install? #39

SUPERCILEX opened this issue Sep 3, 2023 · 4 comments

Comments

@SUPERCILEX
Copy link

Is it possible to ship the PGO/BOLT profile files with a crate such that a cargo install will use them? That would be quite powerful for rust ecosystem tools where people tend to prefer installing from source.

@Kobzol
Copy link
Owner

Kobzol commented Sep 3, 2023

That's an interesting idea. I don't think that it's possible with Cargo today, but even if it was, there are at least two large problems that I see with it:

  • PGO profiles are not portable between targets (Linux/Windows/macOS/...), nor between different rustc versions. This means that you would have to upload pre-generated profiles for many target/compiler combinations, or devise some new, platform/rustc/LLVM independent format. This is a big technical challenge.
  • PGO profiles are specifically tuned to selected workloads. It could be challenging to generate profiles that are general enough that they would improve performance for most users. If the profiles do not fit your workload, your PGO optimized program can actually be slower!

@SUPERCILEX
Copy link
Author

Hmmm, that sounds practically intractable.Maybe a better idea is to make the flow for installing cargo binaries more amenable to pgo?

Currently you'd have to git clone, checkout the latest tag (assuming there even is one), do pgo, and finally cargo pgo install --path (is that a thing?). And you're also left out from any updates, having to manually repeat this whole process each time. It makes more sense to keep around the profiles across updates since probably not all code has changed, and therefore the quality of the profiles will decay rather become useless immediately (I think).

The ideal flow is probably something like: you cargo install as usual, but you can optionally run a separate command at any time to gather profiles for the binary and re-install. These profiles stick around and get reused across updates. Running the optional pgo-this-binary command would wipe the profiles if they came from an old version but append if it's the same crate version letting you build better profiles over time.

That would definitely require an RFC though, so maybe too much of a pain.

@Kobzol
Copy link
Owner

Kobzol commented Sep 4, 2023

This would basically mean that cargo-pgo would need to be integrated as part of cargo, and on top of that a lot of other functionality would have to be added to cargo install. Based on the current maintainer shortage and feature freeze/slowdown of cargo, I don't think that this is going to happen anytime soon.

And I'm not really sure that it's worth all this effort. If you want the fastest possible binary for a specific use-case, you'll want to do more things than just PGO/BOLT (LTO=thin, CGU=1, -C target-cpu=native etc.). cargo install is a tool to provide a reasonably optimized binary with wide platform/CPU support, using PGO and other, more targeted optimizations, is usually done in some custom way and is hard to generalize.

@SUPERCILEX
Copy link
Author

Yeah, it's be quite an effort for sure. Agreed that it's probably not worth it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants