From d3d0e4eee87e01b9f7afa1a8de4fa954660bcab7 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 21 Aug 2024 12:12:37 -0400 Subject: [PATCH 1/3] Fix panic in comparison_kernel benchmarks --- arrow/benches/comparison_kernels.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arrow/benches/comparison_kernels.rs b/arrow/benches/comparison_kernels.rs index 5d18a62d13a1..a0513e7c122b 100644 --- a/arrow/benches/comparison_kernels.rs +++ b/arrow/benches/comparison_kernels.rs @@ -167,9 +167,10 @@ fn add_benchmark(c: &mut Criterion) { let string_right = StringArray::from_iter(array_gen); let string_view_right = StringViewArray::from_iter(string_right.iter()); - let scalar = StringArray::new_scalar("xxxx"); + let string_view_scalar = StringViewArray::new_scalar("xxxx"); + let string_scalar = StringArray::new_scalar("xxxx"); c.bench_function("eq scalar StringArray", |b| { - b.iter(|| eq(&scalar, &string_left).unwrap()) + b.iter(|| eq(&string_scalar, &string_left).unwrap()) }); c.bench_function("lt scalar StringViewArray", |b| { @@ -193,7 +194,7 @@ fn add_benchmark(c: &mut Criterion) { }); c.bench_function("eq scalar StringViewArray", |b| { - b.iter(|| eq(&scalar, &string_view_left).unwrap()) + b.iter(|| eq(&string_view_scalar, &string_view_left).unwrap()) }); c.bench_function("eq StringArray StringArray", |b| { @@ -240,10 +241,18 @@ fn add_benchmark(c: &mut Criterion) { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxx")) }); - c.bench_function("like_utf8view scalar starts with", |b| { + c.bench_function("like_utf8view scalar starts with less than 4 bytes", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxx%")) }); + c.bench_function("like_utf8view scalar starts with more than 4 bytes", |b| { + b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxxxx%")) + }); + + c.bench_function("like_utf8view scalar starts with more than 12 bytes", |b| { + b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxxxxxxxxxxx%")) + }); + c.bench_function("like_utf8view scalar complex", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xx_xx%xxx")) }); From 651d4d4b52c2d615f23656a2c052fad4d19c0268 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 21 Aug 2024 12:16:38 -0400 Subject: [PATCH 2/3] Add other special case equality kernels --- arrow/benches/comparison_kernels.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arrow/benches/comparison_kernels.rs b/arrow/benches/comparison_kernels.rs index a0513e7c122b..49debe84d6d7 100644 --- a/arrow/benches/comparison_kernels.rs +++ b/arrow/benches/comparison_kernels.rs @@ -237,19 +237,28 @@ fn add_benchmark(c: &mut Criterion) { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxx%")) }); - c.bench_function("like_utf8view scalar ends with", |b| { + // StringView has special handling for strings with length <= 12 and length <= 4 + c.bench_function("like_utf8view scalar ends with 4 bytes", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxx")) }); - c.bench_function("like_utf8view scalar starts with less than 4 bytes", |b| { + c.bench_function("like_utf8view scalar ends with 6 bytes", |b| { + b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxxxx")) + }); + + c.bench_function("like_utf8view scalar ends with 13 bytes", |b| { + b.iter(|| bench_like_utf8view_scalar(&string_view_left, "%xxxxxxxxxxxxx")) + }); + + c.bench_function("like_utf8view scalar starts with 4 bytes", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxx%")) }); - c.bench_function("like_utf8view scalar starts with more than 4 bytes", |b| { + c.bench_function("like_utf8view scalar starts with 6 bytes", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxxxx%")) }); - c.bench_function("like_utf8view scalar starts with more than 12 bytes", |b| { + c.bench_function("like_utf8view scalar starts with 13 bytes", |b| { b.iter(|| bench_like_utf8view_scalar(&string_view_left, "xxxxxxxxxxxxx%")) }); From e7347ee27c089baebff4d0120120f2f05d349480 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 21 Aug 2024 12:18:25 -0400 Subject: [PATCH 3/3] Add other benchmarks --- arrow/benches/comparison_kernels.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arrow/benches/comparison_kernels.rs b/arrow/benches/comparison_kernels.rs index 49debe84d6d7..c8aa7dfcf530 100644 --- a/arrow/benches/comparison_kernels.rs +++ b/arrow/benches/comparison_kernels.rs @@ -167,7 +167,6 @@ fn add_benchmark(c: &mut Criterion) { let string_right = StringArray::from_iter(array_gen); let string_view_right = StringViewArray::from_iter(string_right.iter()); - let string_view_scalar = StringViewArray::new_scalar("xxxx"); let string_scalar = StringArray::new_scalar("xxxx"); c.bench_function("eq scalar StringArray", |b| { b.iter(|| eq(&string_scalar, &string_left).unwrap()) @@ -193,7 +192,19 @@ fn add_benchmark(c: &mut Criterion) { }) }); - c.bench_function("eq scalar StringViewArray", |b| { + // StringViewArray has special handling for strings with length <= 12 and length <= 4 + let string_view_scalar = StringViewArray::new_scalar("xxxx"); + c.bench_function("eq scalar StringViewArray 4 bytes", |b| { + b.iter(|| eq(&string_view_scalar, &string_view_left).unwrap()) + }); + + let string_view_scalar = StringViewArray::new_scalar("xxxxxx"); + c.bench_function("eq scalar StringViewArray 6 bytes", |b| { + b.iter(|| eq(&string_view_scalar, &string_view_left).unwrap()) + }); + + let string_view_scalar = StringViewArray::new_scalar("xxxxxxxxxxxxx"); + c.bench_function("eq scalar StringViewArray 13 bytes", |b| { b.iter(|| eq(&string_view_scalar, &string_view_left).unwrap()) });