gh-101260: Return to a simpler output buffer for zlib, bz2 and lzma for better performance. #101279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See the accompanying issue for a detailed explanation. BlocksOutputBuffer was introduced in Python 3.10 and the benchmarks back then showed increased performance on larger output buffers. Smaller output buffers were not benchmarked however. In the accompanying issue I show why the previous buffer scheme works better for smaller output sizes. Since small data packets and streaming is more common than large in-memory compression it is beneficial to switch back to the 3.9 python style of arranging the buffers.
This also leads to a lot less code.
I changed one thing from the pthon 3.9 code: the lzma and bz2 buffer sizes do not follow a complex grow pattern but simply double the buffer (just like the zlib module). This only really hurts large in-memory compression but that is an anti-pattern anyway.