-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-37169: [C++] Zstd compression uses context #48851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
|
|
| : compression_level) {} | ||
|
|
||
| ~ZSTDCodec() override { | ||
| ZSTD_freeCCtx(compression_context_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zstd documentation states that these two free functions can accept nullptr. But if someone thinks that null pointer judgment is needed here, it's fine for me. Or we can wrap it with std::unique_ptr.
https://facebook.github.io/zstd/zstd_manual.html
size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /* accept NULL pointer */
mapleFU
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General idea ok to me, would createCctx Dctx in ctor expansive?
| size_t ret = ZSTD_compress(output_buffer, static_cast<size_t>(output_buffer_len), | ||
| input, static_cast<size_t>(input_len), compression_level_); | ||
| if (compression_context_ == nullptr) { | ||
| compression_context_ = ZSTD_createCCtx(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't would this class be used multi threaded...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in your issue show that the codec methods are not multi-thread safe. But there are many fail unit tests. I will check whether codec is shared in multiple threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TEST_F(TestWriteRecordBatch, WriteWithCompression) will share codec in multiple threads. So the implementation of this PR is not suitable. I will fix it.
I guess that it will create a context every time we call |
51a7bf9 to
ba4bdde
Compare
|
For the record, a similar request was made in #48192 |

Rationale for this change
Reduce zstd compression/decompression resource consumption by reusing context.
What changes are included in this PR?
ZSTDCodecwill create a context lazily.Are these changes tested?
Yes. I improved the benchmark to test different compression level. And I test in my private environment. The above is the benchmark of this PR, and the following is the original one.
Are there any user-facing changes?
No.