-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Chunk based iteration in accumulate_indices
#13451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
90e8930
filter chunk
jayzhan211 d0c8e05
fmt
jayzhan211 f3697b8
acc
jayzhan211 6d9f26c
BitIndexIterator
jayzhan211 3721e74
cleanup
jayzhan211 a889299
count group
jayzhan211 b838c4a
add benches
jayzhan211 e454ae5
revert to fixed chunk based method instead of iterating set_indices
jayzhan211 ef8a859
revert count change
jayzhan211 568f749
clippy
jayzhan211 5c2b4bf
taplo format
jayzhan211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
datafusion/functions-aggregate-common/benches/accumulate.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
extern crate criterion; | ||
|
||
use std::sync::Arc; | ||
|
||
use arrow::array::{ArrayRef, BooleanArray, Int64Array}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use datafusion_functions_aggregate_common::aggregate::groups_accumulator::accumulate::accumulate_indices; | ||
|
||
fn generate_group_indices(len: usize) -> Vec<usize> { | ||
(0..len).collect() | ||
} | ||
|
||
fn generate_values(len: usize, has_null: bool) -> ArrayRef { | ||
if has_null { | ||
let values = (0..len) | ||
.map(|i| if i % 7 == 0 { None } else { Some(i as i64) }) | ||
.collect::<Vec<_>>(); | ||
Arc::new(Int64Array::from(values)) | ||
} else { | ||
let values = (0..len).map(|i| Some(i as i64)).collect::<Vec<_>>(); | ||
Arc::new(Int64Array::from(values)) | ||
} | ||
} | ||
|
||
fn generate_filter(len: usize) -> Option<BooleanArray> { | ||
let values = (0..len) | ||
.map(|i| { | ||
if i % 7 == 0 { | ||
None | ||
} else if i % 5 == 0 { | ||
Some(false) | ||
} else { | ||
Some(true) | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
Some(BooleanArray::from(values)) | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let len = 500_000; | ||
let group_indices = generate_group_indices(len); | ||
let rows_count = group_indices.len(); | ||
let values = generate_values(len, true); | ||
let opt_filter = generate_filter(len); | ||
let mut counts: Vec<i64> = vec![0; rows_count]; | ||
accumulate_indices( | ||
&group_indices, | ||
values.logical_nulls().as_ref(), | ||
opt_filter.as_ref(), | ||
|group_index| { | ||
counts[group_index] += 1; | ||
}, | ||
); | ||
|
||
c.bench_function("Handle both nulls and filter", |b| { | ||
b.iter(|| { | ||
accumulate_indices( | ||
&group_indices, | ||
values.logical_nulls().as_ref(), | ||
opt_filter.as_ref(), | ||
|group_index| { | ||
counts[group_index] += 1; | ||
}, | ||
); | ||
}) | ||
}); | ||
|
||
c.bench_function("Handle nulls only", |b| { | ||
b.iter(|| { | ||
accumulate_indices( | ||
&group_indices, | ||
values.logical_nulls().as_ref(), | ||
None, | ||
|group_index| { | ||
counts[group_index] += 1; | ||
}, | ||
); | ||
}) | ||
}); | ||
|
||
let values = generate_values(len, false); | ||
c.bench_function("Handle filter only", |b| { | ||
b.iter(|| { | ||
accumulate_indices( | ||
&group_indices, | ||
values.logical_nulls().as_ref(), | ||
opt_filter.as_ref(), | ||
|group_index| { | ||
counts[group_index] += 1; | ||
}, | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if just using
set_indices
here is possible to iterate on valid indices?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite surprise that the fixed chunk size (64) is faster than iterating set_indices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it seems it is faster (generating faster code) when valid values are high enough.