Skip to content

bench(arrow): merge with a scalar side over run masks, a NULL scalar and decimals - #11527

Open
mightsleep wants to merge 3 commits into
apache:mainfrom
mightsleep:merge-scalar-bench
Open

mightsleep wants to merge 3 commits into
apache:mainfrom
mightsleep:merge-scalar-bench

Conversation

@mightsleep

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

merge with one scalar side is what DataFusion runs for CASE WHEN c THEN expr ELSE literal END, and today it extends MutableArrayData once per row for the scalar side, about 5 to 6 ns per row. The existing benchmark covers array against non-null scalar for i32 and the byte types on random masks. Before changing the kernel, this adds the shapes the next PR (primitives and decimals) needs to be measured on:

  • array without nulls against a scalar, and array against a NULL scalar (CASE WHEN ... THEN array END)
  • masks made of runs (average 64 and 512, 50 % and 10 % true), as from a clustered or sorted column
  • Decimal128

Boolean and Utf8View follow in a small benchmark PR before the PRs that change those paths.

What changes are included in this PR?

  • create_clustered_array, the same run model as the filter_bits benchmark from bench(arrow-select): filter_bits over batches of random and clustered masks #11271, and four run masks.
  • The scalar-side scenarios run on random and run masks for every type. Decimal128 runs only those scenarios, the existing types keep all of them. Existing benchmark ids are unchanged.
  • 500 ms warm up and 1 s of measurement per group instead of 3 s and 5 s. One merge of 8192 rows takes microseconds, and 448 cases at the default would run about an hour. With this the whole suite takes about 16 minutes. An A/A run of the i32 group moved by 1.6 % on average.

Baseline on main: i32 with a scalar side 5 to 6 ns per row, a NULL scalar 8.7 ns per row, and a run mask (runs_of_512_10pct_true) still 43 µs for 8192 rows, as the kernel goes row by row inside runs too.

Are these changes tested?

Benchmark only. cargo bench -p arrow --bench merge_kernels --features test_utils runs all 448 cases.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the arrow-core Core crates related to representing arrow data label Oct 12, 2026

let mut group =
c.benchmark_group(format!("merge_{ARRAY_LEN}_from_{}", input_generator.name()).as_str());
// One merge of 8192 rows takes microseconds, so the default 3 s warm up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i wonder if we need to cut down the benches in this suite; similar to what we did for zip

and/or reduce from 8192 to a smaller batch size 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes hello, agreed. Cut it down the same way as #10919: one strings (3..20) type instead of short/long strings and bytes, dropped non_null_scalar_vs_null_scalar, and kept two of the four run masks (runs of 64 at 50 %, runs of 512 at 10 %). 448 -> 168 cases, under the 240 on main. I kept 8192 rows: at smaller batches the fixed per-call cost starts to dominate and the per-row difference this suite is meant to show gets harder to see.

@mightsleep

Copy link
Copy Markdown
Contributor Author

Yes hello, one more change: each case now cycles through 64 masks and arrays, as zip_kernels does since #10919. With a single mask the branch predictor learns its 128 words, and on main's kernel that made random masks look 1.2 to 1.45x faster than with fresh ones (i32 array_vs_non_null_scalar/90pct_true 16.6 vs 23.9 µs). Still 168 cases. Also rebased on main for the CI fix.

@mightsleep
mightsleep marked this pull request as draft October 28, 2026 15:11
@mightsleep
mightsleep marked this pull request as ready for review November 6, 2026 12:15
@Rich-T-kid Rich-T-kid added the development-process Internal changes; PRs with this label are excluded from changelog label Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants