-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR includes a new batched iterator API, that yeilds a `Vec<T>` and validity data for batches of items from arrays. It can dynamically dispatch over the type of underlying arrays, so recursive compression should hold. The PR includes implementations for primitve arrays, as well as ALP as a test case for more complex encodings and constant array as its fairly trivial. I also added a bunch of benchmarks to various pieces it touches to have some initial performance numbers and test basic correctness.
- Loading branch information
Showing
14 changed files
with
814 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,7 @@ harness = false | |
[[bench]] | ||
name = "compare" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "iter" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; | ||
use itertools::Itertools; | ||
use vortex::array::PrimitiveArray; | ||
use vortex::iter::VectorizedArrayIter; | ||
use vortex::validity::Validity; | ||
use vortex::variants::ArrayVariants; | ||
|
||
fn std_iter(c: &mut Criterion) { | ||
let data = (0_u32..1_000_000).map(Some).collect_vec(); | ||
c.bench_function("std_iter", |b| { | ||
b.iter_batched(|| data.iter().copied(), do_work, BatchSize::SmallInput) | ||
}); | ||
} | ||
|
||
fn std_iter_no_option(c: &mut Criterion) { | ||
let data = (0_u32..1_000_000).collect_vec(); | ||
c.bench_function("std_iter_no_option", |b| { | ||
b.iter_batched( | ||
|| data.iter().copied(), | ||
|mut iter| { | ||
let mut u = 0; | ||
for n in iter.by_ref() { | ||
u += n; | ||
} | ||
u | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn vortex_iter(c: &mut Criterion) { | ||
let data = PrimitiveArray::from_vec((0_u32..1_000_000).collect_vec(), Validity::AllValid); | ||
|
||
c.bench_function("vortex_iter", |b| { | ||
b.iter_batched( | ||
|| data.as_primitive_array_unchecked().u32_iter().unwrap(), | ||
do_work_vortex, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn vortex_iter_flat(c: &mut Criterion) { | ||
let data = PrimitiveArray::from_vec((0_u32..1_000_000).collect_vec(), Validity::AllValid); | ||
|
||
c.bench_function("vortex_iter_flat", |b| { | ||
b.iter_batched( | ||
|| { | ||
data.as_primitive_array_unchecked() | ||
.u32_iter() | ||
.unwrap() | ||
.flatten() | ||
}, | ||
do_work, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn arrow_iter(c: &mut Criterion) { | ||
let data = arrow_array::UInt32Array::from_iter(0_u32..1_000_000); | ||
c.bench_function("arrow_iter", |b| { | ||
b.iter_batched(|| data.iter(), do_work, BatchSize::SmallInput) | ||
}); | ||
} | ||
|
||
fn do_work( | ||
mut iter: impl Iterator<Item = Option<u32>>, | ||
) -> (u32, impl Iterator<Item = Option<u32>>) { | ||
let mut u = 0; | ||
for n in iter.by_ref() { | ||
u += n.unwrap(); | ||
} | ||
(u, iter) | ||
} | ||
|
||
fn do_work_vortex(iter: VectorizedArrayIter<u32>) -> u32 { | ||
let mut sum = 0; | ||
for batch in iter { | ||
for idx in 0..batch.len() { | ||
if batch.is_valid(idx) { | ||
sum += unsafe { *batch.get_unchecked(idx) }; | ||
} | ||
} | ||
} | ||
|
||
sum | ||
} | ||
|
||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().sample_size(100); | ||
targets = std_iter_no_option, | ||
std_iter, | ||
vortex_iter, | ||
vortex_iter_flat, | ||
arrow_iter, | ||
); | ||
criterion_main!(benches); |
Oops, something went wrong.