Skip to content

Conversation

emmatyping
Copy link
Member

@emmatyping emmatyping commented Oct 12, 2025

Currently, the _BlocksOutputBuffer code creates a list of bytes objects to handle the output data from compression libraries. This ends up being slow due to the output buffer code needing to copy each bytes element of the list into the final bytes object buffer at the end of compression.

The new PyBytesWriter API introduced in PEP 782 is an ergonomic and fast method of writing data into a buffer that will later turn into a bytes object. Benchmarks show that using the PyBytesWriter API is 10-30% faster for decompression across a variety of settings. The performance gains are greatest when the decompressor is very performant, such as for Zstandard. Otherwise the decompressor can bottleneck decompression and the gains are more modest, but still sizable (e.g. zlib)!

Currently, the _BlocksOutputBuffer code creates a list of bytes
objects to handle the output data from compression libraries. This ends
up being slow due to the output buffer code needing to copy each bytes
element of the list into the final bytes object buffer at the end of
compression.

The new PyBytesWriter API introduced in PEP 782 is an ergonomic and fast
method of writing data into a buffer that will later turn into a bytes
object. Benchmarks show that using the PyBytesWriter API is 10-30%
faster for decompression across a variety of settings. The performance
gains are greatest when the decompressor is very performant, such as for
Zstandard. Otherwise the decompressor can bottleneck decompression and
the gains are more modest, but still sizable!
@emmatyping emmatyping added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 12, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @emmatyping for commit ffd48e4 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F139976%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants