zstd icon indicating copy to clipboard operation
zstd copied to clipboard

Zstd doesn't always create RLE blocks

Open terrelln opened this issue 4 months ago • 3 comments

cat <(head -c 1GB /dev/zero) <(echo Hello world) <(head -c 1GB /dev/zero) > file
zstd file

There is a small percent of blocks that aren't emitted as RLE blocks, and instead are emitted as a block with a single sequence.

terrelln avatar Aug 11 '25 19:08 terrelln

Yes, this is a known issue. There is a heuristic that attempts to determine when to test a block for conversion to RLE, but it does not always trigger. We could likely improve this by relaxing the condition, thereby increasing the likelihood that the RLE test is executed.

Cyan4973 avatar Aug 11 '25 20:08 Cyan4973

I think there could be a small improvement to the heuristic. The blocks found are a single match. with 0 literals.

terrelln avatar Aug 12 '25 15:08 terrelln

I believed the heuristic is based on the compressed size of the block, i.e. if the compressed size is "small enough", then it's a hint that it might be a candidate for RLE.

Blocks consisting of a single match with 0 literals should fit in this description. I'm surprised if they are not.

Cyan4973 avatar Aug 12 '25 16:08 Cyan4973