Description
Hi!
Recently I checked Profile-Guided Optimization (PGO) improvements on multiple projects. The results are available here. According to the tests, PGO can help with achieving better performance in many cases similar to lol-html
. I think trying to optimize lol-html
with PGO can be a good idea.
I already did some benchmarks and want to share my results.
Test environment
- Fedora 39
- Linux kernel 6.5.12
- AMD Ryzen 9 5900x
- 48 Gib RAM
- SSD Samsung 980 Pro 2 Tib
- Compiler - Rustc 1.74
- lol-html version: the latest for now from the
master
branch on commit44a7659d1ce018c27ae1f7e7913884bdedf72d71
- Disabled Turbo boost
Benchmark
For benchmark purposes, I use cargo bench
benchmark. For PGO optimization I use cargo-pgo tool. The same benchmark suite was used for the PGO training phase built with cargo pgo bench
. PGO optimized results I got with cargo pgo optimize bench
.
Results
I got the following results:
- PGO optimized compared to Release: https://gist.github.com/zamazan4ik/e838bdc873d026bab9fbe21bfed99a8e
- (just for reference) PGO instrumentation compared to Release: https://gist.github.com/zamazan4ik/c94afd268a1ad39d8f8bbe3f17cf1109
As I interpret the results, PGO measurably improves lol-html
performance in many cases. Since this library is used internally in Cloudflare Workers, such performance improvement can be valuable.
Further steps
I can suggest the following action points:
- Perform more PGO benchmarks on
lol-html
. If it shows improvements - add a note to the documentation about possible improvements inlol-html
performance with PGO. - Providing an easier way (e.g. a build option) to build scripts with PGO can be helpful for the end-users and maintainers since they will be able to optimize
lol-html
according to their workloads.
Testing Post-Link Optimization techniques (like LLVM BOLT) would be interesting too (Clang and Rustc already use BOLT as an addition to PGO) but I recommend starting from the usual PGO.
Here are some examples of how PGO optimization is integrated into other projects:
- Rustc: a CI script for the multi-stage build
- GCC:
- Clang: Docs
- Python:
- Go: Bash script
- V8: Bazel flag
- ChakraCore: Scripts
- Chromium: Script
- Firefox: Docs
- Thunderbird has PGO support too
- PHP - Makefile command and old Centminmod scripts
- MySQL: CMake script
- YugabyteDB: GitHub commit
- FoundationDB: Script
- Zstd: Makefile
- Foot: Scripts
- Windows Terminal: GitHub PR
- Pydantic-core: GitHub PR
- file.d: GitHub PR
- OceanBase: CMake flag