Skip to content

perf(encoding): reuse encoded scratch buffer across streaming blocks #47

@polaz

Description

@polaz

Context

Found during review of #45.

Problem

StreamingEncoder::encode_block() allocates a fresh Vec<u8> (encoded) for every emitted block. On the streaming hot path with large inputs, this adds avoidable allocation churn.

Suggested approach

Add an encoded_scratch: Vec<u8> field to StreamingEncoder, clear() it per block, and reuse the capacity across calls — similar to how FrameCompressor reuses its output buffer.

Files involved

  • zstd/src/encoding/streaming_encoder.rs (line 280)

Time estimate

1h

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumMedium priority — important improvementenhancementNew feature or requestperformancePerformance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions