@@ -13,6 +13,7 @@ use divan::Bencher;
1313use divan:: counter:: ItemsCount ;
1414use mimalloc:: MiMalloc ;
1515use vortex_array:: ArrayRef ;
16+ use vortex_array:: ExecutionCtx ;
1617use vortex_array:: IntoArray ;
1718use vortex_array:: VortexSessionExecute ;
1819use vortex_array:: array_session;
@@ -23,9 +24,14 @@ use vortex_array::dtype::NativePType;
2324use vortex_array:: scalar_fn:: EmptyOptions ;
2425use vortex_array:: scalar_fn:: ScalarFnId ;
2526use vortex_array:: scalar_fn:: VecExecutionArgs ;
27+ use vortex_array:: scalar_fn:: unstable:: row:: InitializedElement ;
28+ use vortex_array:: scalar_fn:: unstable:: row:: InputElement ;
2629use vortex_array:: scalar_fn:: unstable:: row:: RowFn ;
2730use vortex_array:: scalar_fn:: unstable:: row:: RowVisitor ;
31+ use vortex_array:: scalar_fn:: unstable:: row:: UninitElementSink ;
2832use vortex_array:: scalar_fn:: unstable:: row:: execute_rows;
33+ use vortex_array:: validity:: Validity ;
34+ use vortex_buffer:: Buffer ;
2935use vortex_error:: VortexExpect ;
3036use vortex_error:: VortexResult ;
3137use vortex_error:: vortex_ensure;
@@ -56,13 +62,36 @@ const INPUT_SHAPES: &[InputShape] = &[InputShape::PerRowPerRow];
5662/// and that is the difference worth watching.
5763const 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 ) ]
6072enum 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+
6695trait 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 ) ]
95175struct InfallibleBool < T > ( PhantomData < T > ) ;
96176
@@ -100,6 +180,12 @@ struct DeferredBool<T>(PhantomData<T>);
100180#[ derive( Clone ) ]
101181struct DeferredI64 ;
102182
183+ #[ derive( Clone ) ]
184+ struct FilteredOwnedI64 ;
185+
186+ #[ derive( Clone ) ]
187+ struct FilteredSinkI64 ;
188+
103189impl < 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 ) ]
186317fn 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+
218361fn 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+
228381fn bench_row_fn < F : RowFn < Options = EmptyOptions > > (
229382 bencher : Bencher ,
230383 function : & F ,
0 commit comments