-
Notifications
You must be signed in to change notification settings - Fork 169
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
perf: Remove redundant copying of batches after FilterExec #835
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
88252cc
Use custom FilterExec that always uses take with a selection vector
andygrove 67ef326
Remove CopyExec around FilterExec
andygrove 5005006
remove CopyExec on FilterExec inputs to joins
andygrove 160deb8
remove copy before sort in some cases
andygrove 9d5df9d
add comments
andygrove 4267f57
cargo fmt
andygrove 9458cfe
bug fix: check for null when building selection vector
andygrove b0c951b
revert
andygrove d38bacd
use arrow kernel
andygrove adfd6cb
remove unused imports
andygrove 3edac27
add criterion benchmark
andygrove 37c883b
address initial feedback
andygrove 8bc5e8a
add ASF header
andygrove 14e4b16
fix missing imports
andygrove de305d5
Update native/core/src/execution/operators/filter.rs
andygrove 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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,109 @@ | ||
// 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.use arrow::array::{ArrayRef, BooleanBuilder, Int32Builder, RecordBatch, StringBuilder}; | ||
|
||
use arrow::compute::filter_record_batch; | ||
use arrow::datatypes::{DataType, Field, Schema}; | ||
use comet::execution::operators::comet_filter_record_batch; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("filter"); | ||
|
||
let num_rows = 8192; | ||
let num_int_cols = 4; | ||
let num_string_cols = 4; | ||
|
||
let batch = create_record_batch(num_rows, num_int_cols, num_string_cols); | ||
|
||
// create some different predicates | ||
let mut predicate_select_few = BooleanBuilder::with_capacity(num_rows); | ||
let mut predicate_select_many = BooleanBuilder::with_capacity(num_rows); | ||
let mut predicate_select_all = BooleanBuilder::with_capacity(num_rows); | ||
for i in 0..num_rows { | ||
predicate_select_few.append_value(i % 10 == 0); | ||
predicate_select_many.append_value(i % 10 > 0); | ||
predicate_select_all.append_value(true); | ||
} | ||
let predicate_select_few = predicate_select_few.finish(); | ||
let predicate_select_many = predicate_select_many.finish(); | ||
let predicate_select_all = predicate_select_all.finish(); | ||
|
||
// baseline uses Arrow's filter_record_batch method | ||
group.bench_function("arrow_filter_record_batch - few rows selected", |b| { | ||
b.iter(|| filter_record_batch(black_box(&batch), black_box(&predicate_select_few))) | ||
}); | ||
group.bench_function("arrow_filter_record_batch - many rows selected", |b| { | ||
b.iter(|| filter_record_batch(black_box(&batch), black_box(&predicate_select_many))) | ||
}); | ||
group.bench_function("arrow_filter_record_batch - all rows selected", |b| { | ||
b.iter(|| filter_record_batch(black_box(&batch), black_box(&predicate_select_all))) | ||
}); | ||
|
||
group.bench_function("comet_filter_record_batch - few rows selected", |b| { | ||
b.iter(|| comet_filter_record_batch(black_box(&batch), black_box(&predicate_select_few))) | ||
}); | ||
group.bench_function("comet_filter_record_batch - many rows selected", |b| { | ||
b.iter(|| comet_filter_record_batch(black_box(&batch), black_box(&predicate_select_many))) | ||
}); | ||
group.bench_function("comet_filter_record_batch - all rows selected", |b| { | ||
b.iter(|| comet_filter_record_batch(black_box(&batch), black_box(&predicate_select_all))) | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn create_record_batch(num_rows: usize, num_int_cols: i32, num_string_cols: i32) -> RecordBatch { | ||
let mut int32_builder = Int32Builder::with_capacity(num_rows); | ||
let mut string_builder = StringBuilder::with_capacity(num_rows, num_rows * 32); | ||
for i in 0..num_rows { | ||
int32_builder.append_value(i as i32); | ||
string_builder.append_value(format!("this is string #{i}")); | ||
} | ||
let int32_array = Arc::new(int32_builder.finish()); | ||
let string_array = Arc::new(string_builder.finish()); | ||
|
||
let mut fields = vec![]; | ||
let mut columns: Vec<ArrayRef> = vec![]; | ||
let mut i = 0; | ||
for _ in 0..num_int_cols { | ||
fields.push(Field::new(format!("c{i}"), DataType::Int32, false)); | ||
columns.push(int32_array.clone()); // note this is just copying a reference to the array | ||
i += 1; | ||
} | ||
for _ in 0..num_string_cols { | ||
fields.push(Field::new(format!("c{i}"), DataType::Utf8, false)); | ||
columns.push(string_array.clone()); // note this is just copying a reference to the array | ||
i += 1; | ||
} | ||
let schema = Schema::new(fields); | ||
RecordBatch::try_new(Arc::new(schema), columns).unwrap() | ||
} | ||
|
||
fn config() -> Criterion { | ||
Criterion::default() | ||
.measurement_time(Duration::from_millis(500)) | ||
.warm_up_time(Duration::from_millis(500)) | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = config(); | ||
targets = criterion_benchmark | ||
} | ||
criterion_main!(benches); |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
We need
datafusion-execution
?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.
We use
use datafusion::execution::TaskContext
. I guess we were just pulling this in transitively before via thedatafusion
crate rather than being explicit.We may want to avoid bringing in the core
datafusion
crate and just depend directly on the crates that we need.