Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bench: rationalize naming, add n == g / 2 + 1 case
  • Loading branch information
mzabaluev committed Jul 22, 2026
commit f80450a3f5b85f71a4b63c420ba967a12fa023a7
25 changes: 14 additions & 11 deletions datafusion/common/benches/split_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ impl OffsetWidth {
}
}

/// The three split-branch cases, keyed on `n` vs the number of groups `g`.
/// The split-branch cases, keyed on `n` vs the number of groups `g`.
/// `take_n_offsets` allocates for whichever side is smaller (predicate
/// `n < offsets.len() - n`, where `offsets.len() == g + 1`):
///
/// * `shift_larger` (`n = g/4`): copy the smaller prefix out, shift the larger
/// * `n = g/4`: copy the smaller prefix out, shift the larger
/// remainder in place.
/// * `shift_midsize` (`n = g/2`): the balanced point; also the in-place-shift
/// branch, but with source/dest halves disjoint.
/// * `shift_smaller` (`n = g - g/4`): the other branch — allocate the smaller
/// * `n = g/2`: the half-point; also the in-place-shift
/// branch.
/// * `n = g/2 + 1`: one item beyond the half-point,
/// to see if it works better on the other side of the fence.
/// * `n = g - g/4`: the other branch — allocate the smaller
/// remainder, return the larger prefix via `mem::replace`.
fn cases(num_groups: usize) -> [(&'static str, usize); 3] {
fn cases(num_groups: usize) -> [usize; 4] {
[
("shift_larger", num_groups / 4),
("shift_midsize", num_groups / 2),
("shift_smaller", num_groups - num_groups / 4),
num_groups / 4,
num_groups / 2,
num_groups / 2 + 1,
num_groups - num_groups / 4,
]
}

Expand All @@ -78,9 +81,9 @@ fn bench_take_n_offsets(
group.sample_size(sample_size);

for width in [OffsetWidth::I32, OffsetWidth::I64] {
for (branch, n) in cases(num_groups) {
for n in cases(num_groups) {
let id =
BenchmarkId::new(branch, format!("{}_grp_{num_groups}", width.label()));
BenchmarkId::new(format!("grp_{num_groups}_take_{n}"), width.label());
group.bench_function(id, |b| {
// `take_n_offsets` mutates its input, so rebuild a fresh offset
// vector per iteration in the untimed setup. Monomorphize per
Expand Down
28 changes: 15 additions & 13 deletions datafusion/physical-plan/benches/multi_group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,22 @@ fn populate_group_values(
gv
}

/// The two `emit(EmitTo::First(n))` split-branch cases, keyed on `n` vs the
/// The `emit(EmitTo::First(n))` split-branch cases, keyed on `n` vs the
/// accumulated group count `g`. `take_n_offsets`
/// allocates for whichever side is smaller:
///
/// * `shift_larger`: emit a smaller prefix — `n = g / 4`, shift remaining in place.
/// * `shift_mid`: emit the half-sized prefix in existing buffer — `n = g / 2`,
/// allocate and shift the remaining half.
/// * `shift_smaller`: emit a larger prefix in existing buffer — `n = g - g / 4`,
/// * `n = g / 4`: emit the smaller prefix, shift remaining in place.
/// * `n = g / 2`: emit the half-sized prefix, shift remaining in place.
/// * `n = g / 2 + 1`: emit the just-over-half-sized prefix in existing buffer,
/// allocate and shift remaining.
fn emit_first_cases(num_groups: usize) -> [(&'static str, usize); 3] {
/// * `n = g - g / 4`: emit the larger prefix in existing buffer,
/// allocate and shift remaining.
fn emit_first_cases(num_groups: usize) -> [usize; 4] {
[
("shift_larger", num_groups / 4),
("shift_midsize", num_groups / 2),
("shift_smaller", num_groups - num_groups / 4),
num_groups / 4,
num_groups / 2,
num_groups / 2 + 1,
num_groups - num_groups / 4,
]
}

Expand All @@ -588,9 +590,9 @@ fn bench_emit_first_small(c: &mut Criterion) {
let batches =
generate_bytes_batches(width, num_groups, num_groups, DEFAULT_BATCH_SIZE);

for (branch, n) in emit_first_cases(num_groups) {
for n in emit_first_cases(num_groups) {
group.bench_with_input(
BenchmarkId::new(branch, format!("{}_grp_{num_groups}", width.label())),
BenchmarkId::new(format!("grp_{num_groups}_emit_{n}",), width.label()),
&batches,
|b, batches| {
b.iter_batched_ref(
Expand Down Expand Up @@ -619,9 +621,9 @@ fn bench_emit_first_large(c: &mut Criterion) {
let batches =
generate_bytes_batches(width, num_groups, 1_000_000, DEFAULT_BATCH_SIZE);

for (branch, n) in emit_first_cases(num_groups) {
for n in emit_first_cases(num_groups) {
group.bench_with_input(
BenchmarkId::new(branch, format!("{}_grp_{num_groups}", width.label())),
BenchmarkId::new(format!("grp_{num_groups}_emit_{n}",), width.label()),
&batches,
|b, batches| {
b.iter_batched_ref(
Expand Down