Skip to content

Reuse zstd context for better perf #248

@NobodyXu

Description

@NobodyXu

I noticed a new PR on zstd gyscos/zstd-rs#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions