kumarUjjawal commented on code in PR #21575:
URL: https://github.com/apache/datafusion/pull/21575#discussion_r3077240321
##########
datafusion/functions-aggregate/benches/count_distinct.rs:
##########
@@ -150,5 +174,101 @@ fn count_distinct_benchmark(c: &mut Criterion) {
});
}
-criterion_group!(benches, count_distinct_benchmark);
+/// Create group indices with uniform distribution
+fn create_uniform_groups(num_groups: usize) -> Vec<usize> {
+ let mut rng = StdRng::seed_from_u64(42);
+ (0..BATCH_SIZE)
+ .map(|_| rng.random_range(0..num_groups))
+ .collect()
+}
+
+/// Create group indices with skewed distribution (80% in 20% of groups)
+fn create_skewed_groups(num_groups: usize) -> Vec<usize> {
+ let mut rng = StdRng::seed_from_u64(42);
+ let hot_groups = (num_groups / 5).max(1);
+ (0..BATCH_SIZE)
+ .map(|_| {
+ if rng.random_range(0..100) < 80 {
+ rng.random_range(0..hot_groups)
+ } else {
+ rng.random_range(0..num_groups)
+ }
+ })
+ .collect()
+}
+
+fn count_distinct_groups_benchmark(c: &mut Criterion) {
+ let count_fn = Count::new();
+
+ // bench different scenarios
+ let scenarios = [
+ // (name, num_groups, distinct_pct, group_fn)
+ ("sparse_uniform", 10, 80, "uniform"),
+ ("moderate_uniform", 100, 80, "uniform"),
+ ("dense_uniform", 1000, 80, "uniform"),
+ ("sparse_skewed", 10, 80, "skewed"),
+ ("dense_skewed", 1000, 80, "skewed"),
+ ("sparse_high_cardinality", 10, 99, "uniform"),
+ ("dense_low_cardinality", 1000, 20, "uniform"),
+ ];
+
+ for (name, num_groups, distinct_pct, group_type) in scenarios {
+ let n_distinct = BATCH_SIZE * distinct_pct / 100;
+ let values = Arc::new(create_i64_array(n_distinct)) as ArrayRef;
+ let group_indices = if group_type == "uniform" {
+ create_uniform_groups(num_groups)
+ } else {
+ create_skewed_groups(num_groups)
+ };
+
+ let (_schema, args) = prepare_args(DataType::Int64);
+
+ if count_fn.groups_accumulator_supported(args.clone()) {
Review Comment:
I agree that having a pre-optimization benchmark is useful. My concern is
only that the baseline should match the real current execution path. Right now
this benchmark uses a manual per-row fallback that creates a 1-row array for
each row, while DataFusion’s generic grouped fallback batches rows per group.
That means the follow-up PR may show gains against a heavier synthetic
baseline. Could we either benchmark the real fallback path, or rename this to
make clear it is only a synthetic baseline?
--
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]