Skip to content

Commit 374e089

Browse files
authored
feat: impl expand for Buffer & BufferMut (#5270)
Signed-off-by: Alexander Droste <[email protected]>
1 parent 1c1a3ff commit 374e089

File tree

5 files changed

+453
-0
lines changed

5 files changed

+453
-0
lines changed

vortex-compute/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ divan = { workspace = true }
4141
[[bench]]
4242
name = "filter_buffer_mut"
4343
harness = false
44+
45+
[[bench]]
46+
name = "expand_buffer"
47+
harness = false
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
//! Expand benchmarks for `Buffer`.
5+
6+
use divan::Bencher;
7+
use vortex_buffer::Buffer;
8+
use vortex_compute::expand::Expand;
9+
use vortex_mask::Mask;
10+
11+
fn main() {
12+
divan::main();
13+
}
14+
15+
const BUFFER_SIZE: usize = 1024;
16+
17+
const SELECTIVITIES: &[f64] = &[
18+
0.01, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.99,
19+
];
20+
21+
fn create_test_buffer<T>(size: usize) -> Buffer<T>
22+
where
23+
T: Copy + Default + From<u8> + Send + 'static,
24+
{
25+
let mut data = Vec::with_capacity(size);
26+
for i in 0..size {
27+
#[expect(clippy::cast_possible_truncation)]
28+
data.push(T::from((i % 256) as u8));
29+
}
30+
Buffer::from(data)
31+
}
32+
33+
fn generate_mask(len: usize, selectivity: f64) -> Mask {
34+
let mut selection = vec![false; len];
35+
let mut indices: Vec<usize> = (0..len).collect();
36+
37+
// Shuffle indices deterministically.
38+
const SHUFFLE_MULTIPLIER: usize = 13;
39+
for idx in (1..len).rev() {
40+
indices.swap(idx, (idx * SHUFFLE_MULTIPLIER) % (idx + 1));
41+
}
42+
43+
#[expect(clippy::cast_possible_truncation)]
44+
let num_selected = ((len as f64) * selectivity).round() as usize;
45+
for i in 0..num_selected {
46+
selection[indices[i]] = true;
47+
}
48+
49+
Mask::from_iter(selection)
50+
}
51+
52+
#[divan::bench(types = [u8, u32, u64], args = SELECTIVITIES, sample_count = 1000)]
53+
fn expand_selectivity<T: Copy + Default + From<u8> + Send + 'static>(
54+
bencher: Bencher,
55+
selectivity: f64,
56+
) {
57+
bencher
58+
.with_inputs(|| {
59+
let mask = generate_mask(BUFFER_SIZE, selectivity);
60+
let true_count = mask.true_count();
61+
let buffer = create_test_buffer::<T>(true_count);
62+
(buffer, mask)
63+
})
64+
.bench_values(|(buffer, mask)| {
65+
let result = buffer.expand(&mask);
66+
divan::black_box(result);
67+
});
68+
}

0 commit comments

Comments
 (0)