Repository navigation
Use zlib-ng (fast!) rather than mainline stale zlib in binary releases #91349
Description
Activity
zlib-ng is an optimized zlib library with better performance on most architectures (with contributions from the likes of Google, Cloudflare, and Intel). It is API compatible with zlib. https://github.com/zlib-ng/zlib-ng
I believe the only platform we don't use the OS's own zlib on is Windows so I'm tagging this issue Windows.
- added3.11only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usage
on Apr 1, 2022 if this hasn't happened in the 3.11 betas this is presumably bumped to 3.12.
I started taking a look at this and it seems like we can build it without having to worry about their build system by renaming the
zconf.h.inandzconf-ng.h.infiles to remove the.in, and settingZLIB_COMPATpreprocessor in pythoncore.vcxproj (as well as referencing the files).Running test_zlib the only failures seem to be testing for certain failures that no longer fail, but I've got no idea how important they are. Also no indication of the performance impact, or anything else that may change (e.g. new DLL exports, etc.), but it certainly does seem like a feasible drop-in replacement.
- added3.12only security fixesonly security fixesand removed3.11only security fixesonly security fixes
on Jul 17, 2022 @zooba which failures are these? I have accumulated quite some experience with the zlib/gzip formats due to working on python-isal, bindings for the ISA-L library that speeds up zlib-compatible compression by rewriting the algorithms in x86 Assembly language. It is quite good, but not suitable for a drop-in replacement, hence the python-isal project.
Having said that I'd love to help out with anything zlib related in CPython.
I knew I should've kept better track of the changed error messages 😄
Skimming through the tests, I'm pretty sure
test_wbitsfailed in a few places because we expected some "invalid window size" errors that aren't errors with zlib-ng. I don't think any were critical, but I don't know the usage of the library well enough to be sure (e.g. do people expect these errors and change behaviour? or are they always just developer error and cause changes to just make things work?)64 remaining items
Contributions to the linux build as in configure.ac & Makefile.pre.in are welcome so that when a recent enough version of zlib-ng is found, it is preferred over vanilla zlib.
- added a commit that references this issue
on Apr 17, 2025 quick update,
-
I have attempted to adjust the linux build to detect and use zlib-ng, to no success.
the .configure script eludes me.
there might only be 10 people in the world who understand any of it.
any help would be greatly appreciated. -
liblzma just had a new release a few days ago (xz-utils package on linux). https://github.com/tukaani-project/xz/releases
the latest liblzma release 5.8.x is using hardware CRC instructions, it is now as fast as zlib-ng and libdeflate.
I have submitted a PR to expose crc32 from lzma.
after it is merged, I shall do more PR to pick the optimal crc function between zlib/zlibng/liblzma depending on what is available.
-
It would be great to see what the stats are compared to zlib-ng. It has optimizations for different architectures and even instruction sets. So it will perform well on older hardware if that is necessary for your use case.
- added a commit that references this issue
on Jul 20, 2025 - added a commit that references this issue
on Apr 23, 2026 Just a quick update since the Python interpreter transitioned to zlib-ng on Windows, I've performed extensive benchmarks and analysis since we did the transition, you can read here, it's a massive improvement! ->
Faster Python 3.14: faster compression and fixing 28-year-old bugs
Reacted by Hugo van Kemenade and Steve DowerThanks @morotti for the write up. Very interesting. It also seems that my side project of python-zlib-ng is now redundant for windows 3.14 and higher. Less maintenance for me in the future. I hope that zlib-ng gets shipped by distro's soon.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs