RHEL, SLES and Ubuntu for IBM zSystems (aka s390x) ship with a zlib
optimization  that significantly improves deflate and inflate
performance on this platform by using a specialized CPU instruction.
This instruction not only compresses the data, but also computes a
checksum. At the moment Pyhton’s gzip support performs compression and
checksum calculation separately, which creates unnecessary overhead on
The reason is that Python needs to write specific values into gzip
header; and when this support was introduced in year 1997, there was
indeed no better way to do this.
Since v220.127.116.11 (2011) zlib provides inflateGetHeader() and
deflateSetHeader() functions for that, so Python does not have to deal
with the exact header and trailer format anymore.
I would like to contribute a patch that replaces manual creation
of gzip headers and trailers with these functions .
Please let me know what you think.
 gh-??????: Read and write gzip header and trailer with zlib · iii-i/cpython@810dac9 · GitHub