Skip to content

Commit 9fe30c4

Browse files
connortsui20claude
andcommitted
Benchmark the row executor and the null strategies
Progress towards #9128. `row_fn_executor` measures the derived execution loop against a hand-written columnar kernel of the same arithmetic, so the cost of going through `RowFn` is separated from the cost of the operation. `strict_validity` measures the three null strategies against each other across validity densities, which is the evidence behind the per-batch selection rule. `like` gains `like_per_row_distinct_patterns`, which gives every row a distinct pattern of the same shape so the compile cache never hits. Paired with `like_per_row_patterns` it separates the cost of compiling a pattern from the cost of matching against it, which is what a kernel that cannot cache across rows pays. Signed-off-by: Connor Tsui <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent b221142 commit 9fe30c4

4 files changed

Lines changed: 674 additions & 5 deletions

File tree

‎vortex-array/Cargo.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ harness = false
129129
name = "binary_ops"
130130
harness = false
131131

132+
[[bench]]
133+
name = "row_fn_executor"
134+
harness = false
135+
132136
[[bench]]
133137
name = "kleene_bool"
134138
harness = false
@@ -278,3 +282,7 @@ harness = false
278282
[[bench]]
279283
name = "slice_dict_primitive"
280284
harness = false
285+
286+
[[bench]]
287+
name = "strict_validity"
288+
harness = false

‎vortex-array/benches/like.rs‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,9 @@ fn like_regex(bencher: Bencher) {
8787
bench_like(bencher, "h_llo%w%d", LikeOptions::default());
8888
}
8989

90-
#[divan::bench]
91-
fn like_per_row_patterns(bencher: Bencher) {
90+
fn bench_per_row_patterns(bencher: Bencher, patterns: ArrayRef) {
9291
let session = vortex_array::array_session();
9392
let array = strings();
94-
// A non-constant pattern child takes the per-row path; repeated patterns hit the
95-
// compile cache.
96-
let patterns = VarBinViewArray::from_iter_str((0..ARRAY_SIZE).map(|_| "hello%")).into_array();
9793
bencher
9894
.with_inputs(|| {
9995
(
@@ -109,6 +105,35 @@ fn like_per_row_patterns(bencher: Bencher) {
109105
.bench_values(|(array, mut ctx)| array.execute::<BoolArray>(&mut ctx).unwrap());
110106
}
111107

108+
#[divan::bench]
109+
fn like_per_row_patterns(bencher: Bencher) {
110+
// A non-constant pattern child takes the per-row path; repeated patterns hit the
111+
// compile cache.
112+
let patterns = VarBinViewArray::from_iter_str((0..ARRAY_SIZE).map(|_| "%aaa%")).into_array();
113+
bench_per_row_patterns(bencher, patterns);
114+
}
115+
116+
/// The per-row path with the compile cache defeated: every row carries a distinct pattern of the
117+
/// same shape, so each row pays one [`LikePattern`] compilation.
118+
///
119+
/// Paired with [`like_per_row_patterns`] this isolates the cost of compiling a pattern from the cost
120+
/// of matching against it, which is what any kernel that cannot cache across rows would pay.
121+
#[divan::bench]
122+
fn like_per_row_distinct_patterns(bencher: Bencher) {
123+
let patterns = VarBinViewArray::from_iter_str(
124+
(0..ARRAY_SIZE).map(|i| format!("%{}%", distinct_trigram(i))),
125+
)
126+
.into_array();
127+
bench_per_row_patterns(bencher, patterns);
128+
}
129+
130+
/// A distinct three-letter lowercase infix per row, so `ARRAY_SIZE` rows never repeat a pattern
131+
/// while every pattern keeps the same shape and compiles the same way.
132+
fn distinct_trigram(i: usize) -> String {
133+
let letter = |shift: usize| char::from(b'a' + u8::try_from((i >> shift) % 26).unwrap());
134+
[letter(0), letter(5), letter(10)].iter().collect()
135+
}
136+
112137
#[divan::bench]
113138
fn ilike_contains(bencher: Bencher) {
114139
bench_like(

0 commit comments

Comments
 (0)