Skip to content

Add benchmark for array_has/array_has_all/array_has_any - #18729

Merged
2010YOUY01 merged 10 commits into
apache:mainfrom
zhuqi-lucas:benchmark_for_array_has
Nov 24, 2025
Merged

2010YOUY01 merged 10 commits into
apache:mainfrom
zhuqi-lucas:benchmark_for_array_has

Conversation

@zhuqi-lucas

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Add benchmark for array_has/array_has_all/array_has_any before optimization.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@2010YOUY01 2010YOUY01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

I noticed it only benchmarked the case that both needle and haystack are ScalarValue, perhaps we can also benchmark Array cases in the future.

@zhuqi-lucas

Copy link
Copy Markdown
Contributor Author

LGTM, thank you.

I noticed it only benchmarked the case that both needle and haystack are ScalarValue, perhaps we can also benchmark Array cases in the future.

Thank you @2010YOUY01 for review, i agree we can add Array cases as follow-up.

|b, &size| {
let array = (0..size).map(|i| lit(i as i64)).collect::<Vec<_>>();
let list_array = make_array(array);
let needle_array = make_array(vec![lit(0_i64), lit(1_i64), lit(2_i64)]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let list_array = make_array(array);
let needle = lit(0_i64);

b.iter(|| black_box(array_has(list_array.clone(), needle.clone())))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BenchmarkId::new("found_at_start", array_size),
&array_size,
|b, &size| {
let array = (0..size).map(|i| lit(i as i64)).collect::<Vec<_>>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates sequential data which is not very realistic. Consider generating skewed and/or non-sequential uniform data.

let list_array = make_array(array);
let needle = lit((size - 1) as i64);

b.iter(|| black_box(array_has(list_array.clone(), needle.clone())))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For small arrays the cloning operation may dominate the time. Can you use a reference instead ?

@alamb

alamb commented Nov 23, 2025

Copy link
Copy Markdown
Contributor

Shall we merge this PR?

@zhuqi-lucas

Copy link
Copy Markdown
Contributor Author

Shall we merge this PR?

@alamb I think we can merge this PR, at least we have a first version for the benchmark, we can improve it to add more cases in follow-up PRs.

@2010YOUY01
2010YOUY01 added this pull request to the merge queue Nov 24, 2025
Merged via the queue into apache:main with commit 3230048 Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants