Nearing the end of Brett Cannon’s post on premature optimizations
I came upon the Codespeed project and its use case for CPython. I had no idea that there was such a wonderfully automatic and up-to-date way to find out what the historical performances of various Python benchmarks have been. As an example, it’s evident that the
python_startup benchmark has seen an improvement of roughly 15% (calculating that lead me off at a tangent, but let’s ignore that), going from 0.0151 seconds to 0.0127 seconds from October 15, 2021 to November 11, 2021:
This is the kind of thing that if you wanted to verify by yourself would most likely cost you loads of time and be a source of a lot of headaches, unless you’re already familiar with the required tooling, so this seems great as something of a concrete reference.
One of the things that stood out to me was in the Executables section: what on earth is
lto-pgo? As one might have guessed it’s two acronyms:
- LTO: Link Time Optimization
- PGO: Profile Guided Optimization
I’m not savvy enough to even begin explaining what both of those do exactly and will just defer to what the official documentation says and leave a Stack Overflow answer as well:
Configuring Python using
--enable-optimizations --with-lto(PGO + LTO) is recommended for best performance.
So, the Python Speed Center page uses a custom compilation of CPython that is optimized for the best performance, is constantly compiled against the latest revisions, and then ran through various benchmarks. Neat!