async-compression icon indicating copy to clipboard operation
async-compression copied to clipboard

Reuse zstd context for better perf

Open NobodyXu opened this issue 11 months ago • 0 comments

I noticed a new PR on zstd https://github.com/gyscos/zstd-rs/pull/247 that optimizes zstd::stream::Encoder by reusing zstd context:

From profiling, I have found that creating a zstd::stream::Encoder and using it to encode a small amount of bytes (less than 100) takes over 200 microseconds per encode on my machine. The vast majority of this time is related to the creation of new zstd contexts, so this PR adds a simple method on Encoder and Decoder that allows one to supply an external context from zstd_safe instead. With these changes, performance is improved - the previously-mentioned benchmark takes less than 2 microseconds per encode.

from @DouglasDwyer

Seems like a good idea to support this once it is merged.

NobodyXu avatar Sep 23 '23 02:09 NobodyXu