Skip to content

Commit 271e49a

Browse files
authored
Use fixed sized array instead of vector for bitpacked take/filter index grouping (#2915)
1 parent 62b9519 commit 271e49a

File tree

1 file changed

+19
-7
lines changed
  • encodings/fastlanes/src/bitpacking/compute

1 file changed

+19
-7
lines changed

encodings/fastlanes/src/bitpacking/compute/mod.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::mem;
2+
use std::mem::MaybeUninit;
3+
14
use vortex_array::compute::{
25
BetweenFn, BetweenOptions, FilterKernelAdapter, KernelRef, ScalarAtFn, SearchSortedFn, SliceFn,
36
TakeFn, between,
@@ -45,28 +48,37 @@ fn chunked_indices<F: FnMut(usize, &[usize])>(
4548
offset: usize,
4649
mut chunk_fn: F,
4750
) {
48-
let mut indices_within_chunk: Vec<usize> = Vec::with_capacity(1024);
51+
let mut indices_within_chunk = [const { MaybeUninit::<usize>::uninit() }; 1024];
52+
let mut indices_len = 0;
4953

5054
let Some(first_idx) = indices.next() else {
5155
return;
5256
};
5357

5458
let mut current_chunk_idx = (first_idx + offset) / 1024;
55-
indices_within_chunk.push((first_idx + offset) % 1024);
59+
indices_within_chunk[indices_len] = MaybeUninit::new((first_idx + offset) % 1024);
60+
indices_len += 1;
5661
for idx in indices {
5762
let new_chunk_idx = (idx + offset) / 1024;
5863

5964
if new_chunk_idx != current_chunk_idx {
60-
chunk_fn(current_chunk_idx, &indices_within_chunk);
61-
indices_within_chunk.clear();
65+
chunk_fn(current_chunk_idx, unsafe {
66+
mem::transmute::<&[MaybeUninit<usize>], &[usize]>(
67+
&indices_within_chunk[..indices_len],
68+
)
69+
});
70+
indices_len = 0;
6271
}
6372

6473
current_chunk_idx = new_chunk_idx;
65-
indices_within_chunk.push((idx + offset) % 1024);
74+
indices_within_chunk[indices_len] = MaybeUninit::new((idx + offset) % 1024);
75+
indices_len += 1;
6676
}
6777

68-
if !indices_within_chunk.is_empty() {
69-
chunk_fn(current_chunk_idx, &indices_within_chunk);
78+
if indices_len > 0 {
79+
chunk_fn(current_chunk_idx, unsafe {
80+
mem::transmute::<&[MaybeUninit<usize>], &[usize]>(&indices_within_chunk[..indices_len])
81+
});
7082
}
7183
}
7284

0 commit comments

Comments
 (0)