Skip to content

Commit

Permalink
Improved perf of RLE decoding (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Apr 22, 2022
1 parent 9f9f8ea commit dc05110
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ xxhash-rust = { version="0.8.3", optional = true, features = ["xxh64"] }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt"] }
criterion = "0.3"

[features]
default = ["snappy", "gzip", "lz4", "zstd", "brotli", "stream", "bloom_filter"]
snappy = ["snap"]
gzip = ["flate2"]
stream = ["futures", "async-stream"]
bloom_filter = ["xxhash-rust"]

[[bench]]
name = "decode_bitpacking"
harness = false
20 changes: 20 additions & 0 deletions benches/decode_bitpacking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use criterion::{criterion_group, criterion_main, Criterion};

use parquet2::encoding::bitpacking::Decoder;

fn add_benchmark(c: &mut Criterion) {
(10..=20).step_by(2).for_each(|log2_size| {
let size = 2usize.pow(log2_size);

let bytes = (0..size as u32)
.map(|x| 0b01011011u8.rotate_left(x))
.collect::<Vec<_>>();

c.bench_function(&format!("bitpacking 2^{}", log2_size), |b| {
b.iter(|| Decoder::new(&bytes, 1, size).count())
});
})
}

criterion_group!(benches, add_benchmark);
criterion_main!(benches);
2 changes: 2 additions & 0 deletions src/encoding/bitpacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl<'a> Decoder<'a> {
impl<'a> Iterator for Decoder<'a> {
type Item = u32;

#[inline] // -71% improvement in bench
fn next(&mut self) -> Option<Self::Item> {
if self.remaining == 0 {
return None;
Expand All @@ -109,6 +110,7 @@ impl<'a> Iterator for Decoder<'a> {
Some(result)
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(self.remaining, Some(self.remaining))
}
Expand Down

0 comments on commit dc05110

Please sign in to comment.