How we made Python's packaging library 3x faster
4 months ago
- #Python
- #Performance
- #Packaging
- Performance improvements in Python's packaging library, including up to 2x faster Version reading and 3x faster SpecifierSet operations.
- Use of Python 3.15's statistical profiler and PyPI metadata to identify and optimize core packaging constructs.
- Significant speedups achieved through regex optimizations, removing NamedTuple, and reducing duplicate Version creation.
- Introduction of micro-benchmarks with asv to measure performance improvements accurately.
- Collaboration with Damian Shaw and Kevin Turcios to enhance packaging performance, benefiting tools like pip.
- Optimizations include faster regex, lazy computation, caching, and using slots for better memory usage.
- Final performance numbers show reading versions is nearly 2x faster, and checking Python version compatibility is 3x faster.
- Release of packaging 26.0rc1 with these improvements and other features like support for pattern matching and pylock files.