Skip to content

Commit 217c1b8

Browse files
committed
Faster pipelines
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 40a541c commit 217c1b8

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

vortex-array/src/pipeline/driver/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod toposort;
1010
use std::hash::{BuildHasher, Hash, Hasher};
1111

1212
use itertools::Itertools;
13-
use vortex_compute::filter::MaskIndices;
1413
use vortex_dtype::DType;
1514
use vortex_error::{vortex_ensure, VortexResult};
1615
use vortex_mask::Mask;
@@ -310,10 +309,7 @@ impl Pipeline {
310309
if selection.true_count() == 0 {
311310
tail.clear();
312311
} else {
313-
let mut indices = Vec::with_capacity(selection.true_count());
314-
selection.iter_ones(|i| indices.push(i));
315-
let mask_indices = unsafe { MaskIndices::new_unchecked(&indices) };
316-
tail.filter(&mask_indices);
312+
tail.filter(selection);
317313
assert_eq!(tail.len(), selection.true_count());
318314
}
319315
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use crate::pipeline::bit_view::BitView;
5+
use crate::pipeline::N;
6+
use vortex_compute::filter::Filter;
7+
8+
impl<'a, T> Filter<BitView<'a>> for &'a mut [T] {
9+
type Output = ();
10+
11+
fn filter(self, selection: &BitView<'a>) -> Self::Output {
12+
// High density: use iter_zeros to compact by removing gaps
13+
let mut write_idx = 0;
14+
let mut read_idx = 0;
15+
16+
selection.iter_zeros(|zero_idx| {
17+
// Copy elements from read_idx to zero_idx (exclusive) to write_idx
18+
let count = zero_idx - read_idx;
19+
unsafe {
20+
// SAFETY: We assume that the elements are of type E and that the view is valid.
21+
// Using memmove for potentially overlapping regions
22+
std::ptr::copy(
23+
self.as_ptr().add(read_idx),
24+
self.as_mut_ptr().add(write_idx),
25+
count,
26+
);
27+
write_idx += count;
28+
}
29+
read_idx = zero_idx + 1;
30+
});
31+
32+
// Copy any remaining elements after the last zero
33+
unsafe {
34+
std::ptr::copy(
35+
self.as_ptr().add(read_idx),
36+
self.as_mut_ptr().add(write_idx),
37+
N - read_idx,
38+
);
39+
}
40+
}
41+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
mod buffer;
5+
6+
use crate::pipeline::bit_view::BitView;
7+
use vortex_compute::filter::Filter;
8+
use vortex_mask::MaskMut;
9+
use vortex_vector::primitive::{PVectorMut, PrimitiveVectorMut};
10+
use vortex_vector::{match_each_pvector_mut, VectorMut, VectorMutOps};
11+
12+
impl Filter<BitView<'_>> for &mut VectorMut {
13+
type Output = ();
14+
15+
fn filter(self, selection: &BitView<'_>) -> Self::Output {
16+
match self {
17+
VectorMut::Null(_) => {}
18+
VectorMut::Bool(_) => {}
19+
VectorMut::Decimal(_) => {}
20+
VectorMut::Primitive(p) => {
21+
p.filter(selection);
22+
}
23+
VectorMut::String(_) => {}
24+
VectorMut::Binary(_) => {}
25+
VectorMut::List(_) => {}
26+
VectorMut::FixedSizeList(_) => {}
27+
VectorMut::Struct(_) => {}
28+
}
29+
}
30+
}
31+
32+
impl Filter<BitView<'_>> for &mut PrimitiveVectorMut {
33+
type Output = ();
34+
35+
fn filter(self, selection: &BitView<'_>) -> Self::Output {
36+
match_each_pvector_mut!(self, |v| { v.filter(selection) })
37+
}
38+
}
39+
40+
impl<T> Filter<BitView<'_>> for &mut PVectorMut<T> {
41+
type Output = ();
42+
43+
fn filter(self, selection: &BitView<'_>) -> Self::Output {
44+
println!("SEL(): {:?}", selection);
45+
unsafe { self.elements_mut() }.as_mut().filter(selection);
46+
// FIXME(ngates): filter the validity...
47+
*unsafe { self.validity_mut() } = MaskMut::new_true(selection.true_count());
48+
unsafe { self.set_len(selection.true_count()) };
49+
}
50+
}

vortex-array/src/pipeline/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
pub mod bit_view;
55
pub mod driver;
6+
mod filter;
67

78
use vortex_error::{VortexExpect, VortexResult};
89
use vortex_vector::{Vector, VectorMut};

0 commit comments

Comments
 (0)