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

docs: Update performance.md #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zamazan4ik
Copy link

- add documentation about PGO usage for optimizing Rinja's performance

## Profile-Guided Optimization (PGO)

To optimize Rinja's performance, you can compile your application with [Profile-Guided Optimization](https://doc.rust-lang.org/rustc/profile-guided-optimization.html). According to the [tests](https://github.com/mitsuhiko/minijinja/pull/588#issuecomment-2387957123), PGO can improve the library performance by 15%.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We write rinja in lowercase so please update. :)

Could you also explain in the book directly instead of linking to a github issue? The explanations there are great so I think you can mostly copy-paste it as is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We write rinja in lowercase so please update. :)

Sorry - I just copied it from line 30th "... Rinja's derive macros" ;)

Could you also explain in the book directly instead of linking to a github issue? The explanations there are great so I think you can mostly copy-paste it as is.

Sure. Which details should be copied from the GitHub issue to the book? Just asking because I am sure that you don't need all the details (like my test env). Better clarify upfront then rework multiple times.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything needed to be able to use PGO. What you need to install etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructions about how to use PGO for Rust programs are described in the official Rustc docs that I already linked to the docs: https://doc.rust-lang.org/rustc/profile-guided-optimization.html - it's an official instruction about how to implement PGO for Rust programs (including a note about about cargo-pgo). My GitHub issue describes how to reproduce my benchmark results. I guessed that target users are not interested in reproducing my benchmarks but interested in optimizing their rinja-based apps.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe just remove the GitHub link at all from the docs? :)

@Kijewski
Copy link
Collaborator

Kijewski commented Oct 3, 2024

Interesting! @zamazan4ik, do you know if it's possible to see/evaluate the results of the profiling? If it is, then maybe we could add a few likely!()/unlikely!() hints to the code.

@zamazan4ik
Copy link
Author

Interesting! @zamazan4ik, do you know if it's possible to see/evaluate the results of the profiling? If it is, then maybe we could add a few likely!()/unlikely!() hints to the code.

Well, it's possible to achieve via analyzing "before" vs "after" assembly LLVM IR and guessing the required changes (or extracting optimization feedback from LLVM). However, I highly recommend don't do it in practice since this way has many drawbacks:

  • It's not possible to bring all PGO-based information to the compiler via intrinsic. Like inline weights - the inline attribute doesn't have such a precision
  • Different people can have different workloads and your manually written hints can not be the best options for their cases. The conflicts between user hints and PGO-provided information are the dark area in compilers and are completely undocumented - this behavior can be changed from one compiler release to another.

So my personal recommendation is just leaving the things to PGO and spend your efforts to something more important to the projects like high-level/algortihm optimizations that still cannot be done by compilers (at least yet).

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

Successfully merging this pull request may close these issues.

3 participants