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

[IDEA] Optimizing wheels with PGO #46

Closed
jeertmans opened this issue Feb 12, 2024 · 1 comment
Closed

[IDEA] Optimizing wheels with PGO #46

jeertmans opened this issue Feb 12, 2024 · 1 comment
Labels
enhancement New feature or request not-worth A not-so-worth optimization, that has zero or very limited positive impact on performances

Comments

@jeertmans
Copy link
Owner

jeertmans commented Feb 12, 2024

This feature suggestion is highly inspired from maciejhirsz/logos#374, a repository I maintain.

Actually, the idea would be to follow what pydantic-core does, see https://github.com/pydantic/pydantic-core/blob/44621f1dee5160c737a0749d21e0b2118fa99705/.github/workflows/ci.yml#L464-L557, to generate more performant code.

The setup for DiffeRT should be as follows:

  1. Install the necessary LLVM tools:
rustup component add llvm-tools-preview
  1. Compile code so that it can generate profiles:
RUSTFLAGS='-Cprofile-generate=/tmp/pgo-data/profdata' maturin build --release --out pgo-wheel
  1. Install the library from new wheels:
pdm run python -m pip install differt --no-index --no-deps --find-links pgo-wheel --force-reinstall
  1. Actually generate profiles by running code that uses wheels:
pdm run pytest --benchmark-only tests
  1. Merge profiles. The actual path to llvm-profdata may change, see https://doc.rust-lang.org/rustc/profile-guided-optimization.html.
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o /tmp/pgo-data/merged.profdata /tmp/pgo-data/profdata
  1. Generate optimized build:
RUSTFLAGS='-Cprofile-use=/tmp/pgo-data/merged.profdata' maturin build --release --out dist

The only question I have is whether this is actually useful (did run a benchmark after, but not improvement noticed). I might need to write better benchmarks (that target actually what I want to optimize).

@jeertmans jeertmans added the enhancement New feature or request label Feb 12, 2024
jeertmans added a commit that referenced this issue Feb 14, 2024
jeertmans added a commit that referenced this issue Feb 14, 2024
jeertmans added a commit that referenced this issue Feb 14, 2024
* fix(ci): force stable toolchain

* chore(ci): do PGO optimization in CI and benchmark it

Related to #46.

* fix(ci): ensure pip

* fix(ci): specify tests folder to avoid doctest issue

* fix(ci): force stable toolchain

* chore(ci): do PGO optimization in CI and benchmark it

Related to #46.

* fix(ci): ensure pip

* fix(ci): specify tests folder to avoid doctest issue

* fix(c): reset publish ci

* chore(ci): remove useless profile

* chore(ci): try different output

* chore(ci): rename pgo run

* chore(ci): nicer output

* chore(ci): remove useless quotes
@jeertmans jeertmans added the not-worth A not-so-worth optimization, that has zero or very limited positive impact on performances label Feb 14, 2024
@jeertmans
Copy link
Owner Author

Added PGO benchmarks in GitHub CI with #48, and it currently does not seem worth performing PGO, but maybe we will re-open this in the future.

@jeertmans jeertmans changed the title Idea: optimizing wheels with PGO [IDEA] Optimizing wheels with PGO Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request not-worth A not-so-worth optimization, that has zero or very limited positive impact on performances
Projects
None yet
Development

No branches or pull requests

1 participant