Evaluate using Profile-Guided Optimization (PGO) and Post-Link Optimization (PLO)
Describe the Bug
Hi!
Another optimization idea, in addition to the already completed https://github.com/facebook/pyrefly/issues/214
Recently I checked Profile-Guided Optimization (PGO) improvements on multiple projects (including many LSP servers like Clangd and Rust Analyzer) - the results are available in the awesome-pgo repo. Since PGO has helped in many similar to pyrefly cases, I think it would be a good idea to try optimizing pyrefly by applying PGO to it.
I can suggest the following things to do:
- We need to perform PGO benchmarks on
pyrefly. If it shows improvements - add a note about possible improvements to the documentation. Providing an easier way (e.g. a build option) to build scripts to buildpyreflywith PGO can be useful for the end-users too. - It will be a good idea to integrate building with PGO into your CI pipelines. In this case, users will get already PGO-optimized binaries from the website
Here you can find different materials about PGO: benchmarks for multiple apps, examples of how PGO is already integrated with various projects, PGO support in multiple Rust compilers, and some PGO-related pieces of advice. For Rust-based applications, I recommend starting with cargo-pgo.
After PGO, I suggest evaluating the Post-Link Optimization (with tools like LLVM BOLT) - it can give more aggressive optimizations even after PGO. However, starting with regular PGO will be easier to do. Since LLVM BOLT is mainly developed by Facebook/Meta - probably you are a bit more motivated to give it a try ;)
Thank you.
Sandbox Link
N/A
(Only applicable for extension issues) IDE Information
N/A
Thanks for the suggestions - we'll take a look in a bit, when the CI pipeline isn't changing as much. I'd expect 5-15% improvement from these changes.