Skip to content

Commit 6c4b963

Browse files
authored
Benchmark RowFn filtered fallback (#9736)
## Summary - Tracking Issue: #9130 - Comparison target: #9645 Adds a focused baseline for the RowFn fallback under comparison. `FilteredI64` declares `DENSE_SAFE = false`, so partially valid inputs select valid-only execution, and it declines null-tolerant decoding, so direct valid-row execution is unavailable. The remaining path is filter-and-scatter on `develop` and filtered-row execution with #9645. ## Changes Benchmarks owned and sink outputs with all-valid, one-null-in-eight, and nine-nulls-in-ten inputs. The partial-validity cases force the fallback, while the all-valid cases bypass it as unchanged controls. All cases run on the native AVX2, AVX-512, and NEON CodSpeed legs. --------- Signed-off-by: Connor Tsui <[email protected]>
1 parent 4161afd commit 6c4b963

1 file changed

Lines changed: 153 additions & 0 deletions

File tree

‎vortex-array/benches/row_fn_output.rs‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use divan::Bencher;
1313
use divan::counter::ItemsCount;
1414
use mimalloc::MiMalloc;
1515
use vortex_array::ArrayRef;
16+
use vortex_array::ExecutionCtx;
1617
use vortex_array::IntoArray;
1718
use vortex_array::VortexSessionExecute;
1819
use vortex_array::array_session;
@@ -23,9 +24,14 @@ use vortex_array::dtype::NativePType;
2324
use vortex_array::scalar_fn::EmptyOptions;
2425
use vortex_array::scalar_fn::ScalarFnId;
2526
use vortex_array::scalar_fn::VecExecutionArgs;
27+
use vortex_array::scalar_fn::unstable::row::InitializedElement;
28+
use vortex_array::scalar_fn::unstable::row::InputElement;
2629
use vortex_array::scalar_fn::unstable::row::RowFn;
2730
use vortex_array::scalar_fn::unstable::row::RowVisitor;
31+
use vortex_array::scalar_fn::unstable::row::UninitElementSink;
2832
use vortex_array::scalar_fn::unstable::row::execute_rows;
33+
use vortex_array::validity::Validity;
34+
use vortex_buffer::Buffer;
2935
use vortex_error::VortexExpect;
3036
use vortex_error::VortexResult;
3137
use vortex_error::vortex_ensure;
@@ -56,13 +62,36 @@ const INPUT_SHAPES: &[InputShape] = &[InputShape::PerRowPerRow];
5662
/// and that is the difference worth watching.
5763
const CONSTANT_SHAPES: &[InputShape] = &[InputShape::PerRowConstant, InputShape::ConstantPerRow];
5864

65+
const VALIDITY_PATTERNS: &[ValidityPattern] = &[
66+
ValidityPattern::AllValid,
67+
ValidityPattern::OneNullInEight,
68+
ValidityPattern::NineNullsInTen,
69+
];
70+
5971
#[derive(Clone, Copy, Debug)]
6072
enum InputShape {
6173
PerRowPerRow,
6274
PerRowConstant,
6375
ConstantPerRow,
6476
}
6577

78+
#[derive(Clone, Copy, Debug)]
79+
enum ValidityPattern {
80+
AllValid,
81+
OneNullInEight,
82+
NineNullsInTen,
83+
}
84+
85+
impl ValidityPattern {
86+
fn is_valid(self, index: usize) -> bool {
87+
match self {
88+
Self::AllValid => true,
89+
Self::OneNullInEight => !index.is_multiple_of(8),
90+
Self::NineNullsInTen => index.is_multiple_of(10),
91+
}
92+
}
93+
}
94+
6695
trait BenchPrimitive: NativePType {
6796
fn per_row(offset: usize) -> ArrayRef;
6897

@@ -91,6 +120,57 @@ impl BenchPrimitive for i64 {
91120
}
92121
}
93122

123+
/// Primitive input that forces partially valid batches through the filtered fallback.
124+
///
125+
/// `DENSE_SAFE = false` selects valid-only execution. This type inherits the conservative
126+
/// null-tolerant decode implementation, so direct valid-row execution declines the original
127+
/// nullable input. A partially valid input must therefore use the executor's filtered fallback.
128+
struct FilteredI64;
129+
130+
// SAFETY: the view is a native slice, and its reported length is the slice length.
131+
unsafe impl InputElement for FilteredI64 {
132+
type Column = Buffer<i64>;
133+
type Constant = i64;
134+
type View<'a> = &'a [i64];
135+
type Elem<'a> = i64;
136+
137+
const DENSE_SAFE: bool = false;
138+
const DECODE_INFALLIBLE: bool = true;
139+
140+
fn validate(dtype: &DType) -> VortexResult<()> {
141+
<i64 as InputElement>::validate(dtype)
142+
}
143+
144+
fn decode(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self::Column> {
145+
<i64 as InputElement>::decode(array, ctx)
146+
}
147+
148+
fn decode_constant(array: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Self::Constant> {
149+
<i64 as InputElement>::decode_constant(array, ctx)
150+
}
151+
152+
fn get(column: &Self::Column, index: usize) -> Self::Elem<'_> {
153+
column[index]
154+
}
155+
156+
fn get_constant(constant: &Self::Constant) -> Self::Elem<'_> {
157+
*constant
158+
}
159+
160+
fn view(column: &Self::Column) -> Self::View<'_> {
161+
column.as_slice()
162+
}
163+
164+
fn get_from_view<'a>(view: &Self::View<'a>, index: usize) -> Self::Elem<'a> {
165+
view[index]
166+
}
167+
168+
unsafe fn get_from_view_unchecked<'a>(view: &Self::View<'a>, index: usize) -> Self::Elem<'a> {
169+
// SAFETY: forwarded from this method's contract.
170+
unsafe { *view.get_unchecked(index) }
171+
}
172+
}
173+
94174
#[derive(Clone)]
95175
struct InfallibleBool<T>(PhantomData<T>);
96176

@@ -100,6 +180,12 @@ struct DeferredBool<T>(PhantomData<T>);
100180
#[derive(Clone)]
101181
struct DeferredI64;
102182

183+
#[derive(Clone)]
184+
struct FilteredOwnedI64;
185+
186+
#[derive(Clone)]
187+
struct FilteredSinkI64;
188+
103189
impl<T: BenchPrimitive> RowFn for InfallibleBool<T> {
104190
type Options = EmptyOptions;
105191

@@ -181,6 +267,51 @@ impl RowFn for DeferredI64 {
181267
}
182268
}
183269

270+
impl RowFn for FilteredOwnedI64 {
271+
type Options = EmptyOptions;
272+
273+
const ARG_NAMES: &'static [&'static str] = &["value"];
274+
const INFALLIBLE: bool = true;
275+
276+
fn id(&self) -> ScalarFnId {
277+
static ID: CachedId = CachedId::new("bench.row_fn_output.filtered_owned_i64");
278+
*ID
279+
}
280+
281+
fn dispatch<V: RowVisitor>(
282+
&self,
283+
_options: &Self::Options,
284+
_args: &[DType],
285+
visitor: V,
286+
) -> VortexResult<V::VisitResult> {
287+
visitor.visit::<(FilteredI64,), i64>(|(value,)| value.wrapping_add(1))
288+
}
289+
}
290+
291+
impl RowFn for FilteredSinkI64 {
292+
type Options = EmptyOptions;
293+
294+
const ARG_NAMES: &'static [&'static str] = &["value"];
295+
const INFALLIBLE: bool = true;
296+
297+
fn id(&self) -> ScalarFnId {
298+
static ID: CachedId = CachedId::new("bench.row_fn_output.filtered_sink_i64");
299+
*ID
300+
}
301+
302+
fn dispatch<V: RowVisitor>(
303+
&self,
304+
_options: &Self::Options,
305+
_args: &[DType],
306+
visitor: V,
307+
) -> VortexResult<V::VisitResult> {
308+
visitor.visit_into::<(FilteredI64,), UninitElementSink<i64>, _>((), |(value,), output| {
309+
// SAFETY: `output` is the `UninitElementSink` row supplied for this callback.
310+
unsafe { InitializedElement::write(output, value.wrapping_add(1)) }
311+
})
312+
}
313+
}
314+
184315
#[vortex_bench_support::cpu_features]
185316
#[divan::bench(types = [i32, i64], args = INPUT_SHAPES)]
186317
fn infallible_bool<T: BenchPrimitive>(bencher: Bencher, &shape: &InputShape) {
@@ -215,6 +346,18 @@ fn deferred_i64(bencher: Bencher, &shape: &InputShape) {
215346
bench_row_fn(bencher, &DeferredI64, make_args::<i64>(shape));
216347
}
217348

349+
#[vortex_bench_support::cpu_features]
350+
#[divan::bench(args = VALIDITY_PATTERNS)]
351+
fn filtered_owned_i64(bencher: Bencher, &validity: &ValidityPattern) {
352+
bench_row_fn(bencher, &FilteredOwnedI64, make_filtered_args(validity));
353+
}
354+
355+
#[vortex_bench_support::cpu_features]
356+
#[divan::bench(args = VALIDITY_PATTERNS)]
357+
fn filtered_sink_i64(bencher: Bencher, &validity: &ValidityPattern) {
358+
bench_row_fn(bencher, &FilteredSinkI64, make_filtered_args(validity));
359+
}
360+
218361
fn make_args<T: BenchPrimitive>(shape: InputShape) -> VecExecutionArgs {
219362
let args = match shape {
220363
InputShape::PerRowPerRow => vec![T::per_row(0), T::per_row(1)],
@@ -225,6 +368,16 @@ fn make_args<T: BenchPrimitive>(shape: InputShape) -> VecExecutionArgs {
225368
VecExecutionArgs::new(args, ROWS)
226369
}
227370

371+
fn make_filtered_args(validity: ValidityPattern) -> VecExecutionArgs {
372+
let values = PrimitiveArray::new(
373+
(0..ROWS).map(|index| index as i64).collect::<Buffer<_>>(),
374+
Validity::from_iter((0..ROWS).map(|index| validity.is_valid(index))),
375+
)
376+
.into_array();
377+
378+
VecExecutionArgs::new(vec![values], ROWS)
379+
}
380+
228381
fn bench_row_fn<F: RowFn<Options = EmptyOptions>>(
229382
bencher: Bencher,
230383
function: &F,

0 commit comments

Comments
 (0)