Repository navigation
Conversation
ZstdContext.compress called zstd.compress(), which creates and frees a compression context for every message.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PYTHON-XXXX
Changes in this PR
ZstdContext.compresscalledzstd.compress()for every message, which creates and frees a zstd compression context each time. For a small message, setting up the context costs more than compressing it.It now keeps one
ZstdCompressorper thread in athreading.local, and compresses each message as a complete frame withcompress(data, ZstdCompressor.FLUSH_FRAME).The output is a standard zstd frame, the same as before, and decompression is unchanged.
ZstdContext.compress, document-like payloads, master → this PR. Python 3.12,backports.zstd(zstd 1.5.7), Intel Core Ultra 7 265, one pinned core:Compressed sizes are unchanged.
Test Plan
test_zstd_compressor_reused_across_messages: 64 messages of different sizes through the same thread's compressor. Each one decompresses withzstd.decompressand withpymongo.compression_support.decompress.test_zstd_compress_from_many_threads: 8 threads compress and decompress 200 messages each.test/test_compression_support.py: 36 passed, 4 skipped (python-snappy not installed).COMPRESSORS=zstd:test/test_client.py -k compress(2 passed), andtest/test_collection.py,test/test_cursor.pyandtest/test_bulk.py(187 passed, 15 skipped because they need a replica set).ruff checkandruff format --checkpass on the changed files.Checklist
Checklist for Author
Checklist for Reviewer
With Claude's help.