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

Supporting PGO builds from maturin #1840

Open
davidhewitt opened this issue Nov 7, 2023 · 3 comments
Open

Supporting PGO builds from maturin #1840

davidhewitt opened this issue Nov 7, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@davidhewitt
Copy link
Member

In pydantic-core we have been building with PGO for x86_64 Windows and Ubuntu for some time, and we're now also looking at GitHub's new M1 runners to run PGO optimization for arm macOS. pydantic/pydantic-core#1063

This is in a sort of grey area where we can make it work with maturin by passing in the PGO RUSTFLAGS directly and then running normal maturin build steps. We could call it an orthogonal problem which maturin doesn't need to solve.

There are two reasons why I think it would be nice for maturin to have firsthand support for PGO builds:

  • We can then make it easy for all Rust extension authors to PGO optimize their builds
  • We can only pass one --interpreter to build with PGO, which makes our build matrix very large (M platforms, N Python versions). It would be nice to be able to pass --interpreter 3.7 3.8 ... with all versions to make use of better build caching and reduce the number of jobs.

To have support for PGO, I think maturin would need to:

  1. build the PGO-instrumented wheel for a given interpreter
  2. install that wheel into a temporary virtual environment and run some step to generate PGO samples (we'd need configuration for this)
  3. build the PGO-optimized wheel using the samples
    ... and repeat the above for each interpreter in turn.

I think all the configuration that would be needed is the set of packages to install into the temporary virtual environment and then a script to run to generate the PGO sample. The script could even be responsible for installing the dependencies, reducing to a single configuration entry, but then it probably needs to be a shell script and it gets a little harder to be cross-platform.

There is maybe an argument to leave all of this functionality to maturin-action. A nice thing about putting this directly in maturin is that the PGO build could then also be done locally, e.g. to benchmark it.

cc @konstin I took a quick look at the ruff workflow and it looks like you don't make use of PGO builds, is that something you tried and found it wasn't worth it, or just not ever looked into? In pydantic-core we won about 20-30% speedup from PGO, so potentially there is a nice ruff performance win to celebrate sitting on the table 😄

@davidhewitt davidhewitt added the enhancement New feature or request label Nov 7, 2023
@konstin
Copy link
Member

konstin commented Nov 7, 2023

cc @konstin I took a quick look at the ruff workflow and it looks like you don't make use of PGO builds, is that something you tried and found it wasn't worth it, or just not ever looked into? In pydantic-core we won about 20-30% speedup from PGO, so potentially there is a nice ruff performance win to celebrate sitting on the table 😄

I haven't actually looked at it, 20-30% is massive!

@konstin
Copy link
Member

konstin commented Nov 24, 2023

I tried it for ruff an ran into am LLVM bug: Kobzol/cargo-pgo#32

@davidhewitt
Copy link
Member Author

Ah how disappointing 😢

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

No branches or pull requests

2 participants