c-blosc2 icon indicating copy to clipboard operation
c-blosc2 copied to clipboard

What's the recommended way of reusing one context for buffers of different size?

Open v-chernyshev opened this issue 5 years ago • 0 comments

Good afternoon, I did a quick test of blosc V2 and saw that its compression ratio was much worse than what I used to get with V1. I've traced it to the btune_next_blocksize function: https://github.com/Blosc/c-blosc2/blob/50a7357108e5efe1e1b9c3b407d6214f7e907e00/blosc/btune.c#L53-L56

Essentially what happens is that when context->blocksize is set to zero it is eventually initialised based on the very first buffer that is passed into blosc2_compress_ctx, in my case it was a very small array that caused the calculated blocksize to be set to 96. Subsequent calls to btune_next_blocksize then treat this 96 as a user-supplied block size, which leads to almost no compression of bigger buffers.

The only way I see to "fix" it while, at the same time, keeping automatic block size deduction, is to include context.h and reset blocksize to zero before calling blosc2_compress_ctx, but there is a comment in the header that says that the context is an opaque type. Is there a better way to do it? Thanks!

v-chernyshev avatar Jul 16 '20 16:07 v-chernyshev