alamb commented on code in PR #21487:
URL: https://github.com/apache/datafusion/pull/21487#discussion_r3066186666
##########
datafusion/functions-aggregate/benches/first_last.rs:
##########
@@ -72,92 +74,129 @@ fn prepare_groups_accumulator(is_first: bool) -> Box<dyn
GroupsAccumulator> {
}
}
-fn prepare_accumulator(is_first: bool) -> Box<dyn Accumulator> {
- let schema = Arc::new(Schema::new(vec![
- Field::new("value", DataType::Int64, true),
- Field::new("ord", DataType::Int64, true),
- ]));
-
- let order_expr = col("ord", &schema).unwrap();
- let sort_expr = PhysicalSortExpr {
- expr: order_expr,
- options: SortOptions::default(),
- };
-
- let value_field: Arc<Field> = Field::new("value", DataType::Int64,
true).into();
- let accumulator_args = AccumulatorArgs {
- return_field: Arc::clone(&value_field),
- schema: &schema,
- expr_fields: &[value_field],
- ignore_nulls: false,
- order_bys: std::slice::from_ref(&sort_expr),
- is_reversed: false,
- name: if is_first {
- "FIRST_VALUE(value ORDER BY ord)"
- } else {
- "LAST_VALUE(value ORDER BY ord)"
- },
- is_distinct: false,
- exprs: &[col("value", &schema).unwrap()],
- };
-
+fn create_trivial_accumulator(
+ is_first: bool,
+ ignore_nulls: bool,
+) -> Box<dyn Accumulator> {
if is_first {
- FirstValue::new().accumulator(accumulator_args).unwrap()
+ Box::new(
+ TrivialFirstValueAccumulator::try_new(&DataType::Int64,
ignore_nulls)
+ .unwrap(),
+ )
} else {
- LastValue::new().accumulator(accumulator_args).unwrap()
+ Box::new(
+ TrivialLastValueAccumulator::try_new(&DataType::Int64,
ignore_nulls).unwrap(),
+ )
}
}
#[expect(clippy::needless_pass_by_value)]
-fn convert_to_state_bench(
+#[expect(clippy::too_many_arguments)]
+fn evaluate_bench(
c: &mut Criterion,
is_first: bool,
+ emit_to: EmitTo,
name: &str,
values: ArrayRef,
+ ord: ArrayRef,
opt_filter: Option<&BooleanArray>,
+ num_groups: usize,
) {
+ let n = values.len();
+ let group_indices: Vec<usize> = (0..n).map(|i| i % num_groups).collect();
+
c.bench_function(name, |b| {
- b.iter(|| {
- let accumulator = prepare_groups_accumulator(is_first);
- black_box(
- accumulator
- .convert_to_state(std::slice::from_ref(&values),
opt_filter)
- .unwrap(),
- )
+ b.iter_custom(|iters| {
+ // Every `evaluate` call mutates the accumulator, so prebuild
`iters` accumulators
+ let mut accumulators: Vec<Box<dyn GroupsAccumulator>> = (0..iters)
Review Comment:
Why are we creating more than one accumulator?
I think the important benchmark is a single accumuatlor and then merge
multiple batches per iteration. This seems like it merges one batch per
iteration across multiple accumulators?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]