Skip to content

Commit 32ca194

Browse files
authored
Invert compression ratio in BtrBlocksCompressedWriter (#2839)
compression ratio is often [defined](https://en.wikipedia.org/wiki/Data_compression_ratio#Definition) as `before / after` ("higher is better"), that's also what we do in the BtrBlocks compressor, so it seems like making it consistent across the codebase makes sense. ~I thought there's another place we use the term, but I couldn't find it.~ I think it was when we store the previous chunk's compression ratio, got it before merging.
1 parent 16b312f commit 32ca194

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

vortex-file/src/strategy.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ impl LayoutWriter for BtrBlocksCompressedWriter {
144144
encode_children_like(canonical_chunk.clone().into_array(), prev_chunk)?
145145
{
146146
let ratio =
147-
encoded_chunk.nbytes() as f64 / canonical_chunk.as_ref().nbytes() as f64;
147+
canonical_chunk.as_ref().nbytes() as f64 / encoded_chunk.nbytes() as f64;
148148

149-
// not sure this condition is right, but the idea is to make sure the ratio is within the expected drift.
150-
// If it isn't we fall back to the compressor.
151-
if ratio < prev_compression.ratio * COMPRESSION_DRIFT_THRESHOLD {
149+
// Make sure the ratio is within the expected drift, if it isn't we fall back to the compressor.
150+
if ratio > prev_compression.ratio / COMPRESSION_DRIFT_THRESHOLD {
152151
Some(encoded_chunk)
153152
} else {
154153
log::trace!(
155-
"Compressed to a ratio of {ratio}, which is above the threshold of {}",
154+
"Compressed to a ratio of {ratio}, which is below the threshold of {}",
156155
prev_compression.ratio * COMPRESSION_DRIFT_THRESHOLD
157156
);
158157
None
@@ -174,7 +173,7 @@ impl LayoutWriter for BtrBlocksCompressedWriter {
174173
let compressed = BtrBlocksCompressor.compress_canonical(canonical_chunk)?;
175174
self.previous_chunk = Some(PreviousCompression {
176175
chunk: compressed.clone(),
177-
ratio: compressed.nbytes() as f64 / canonical_size,
176+
ratio: canonical_size / compressed.nbytes() as f64,
178177
});
179178
compressed
180179
}

0 commit comments

Comments
 (0)