-
Notifications
You must be signed in to change notification settings - Fork 1.8k
perf: improve performance of vectorized_equal_to for PrimitiveGroupValueBuilder in multi group by aggregation
#17977
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
Changes from all commits
1eb2d6a
e5b65bd
01dd5c9
cd99e29
0c6295c
825b8c7
f19d439
f31b5c0
dd73823
5b2704f
27d8026
d5b5caa
0a6f6d3
c201d6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,85 @@ where | |
| nulls: MaybeNullBufferBuilder::new(), | ||
| } | ||
| } | ||
|
|
||
| fn vectorized_equal_to_non_nullable( | ||
| &self, | ||
| lhs_rows: &[usize], | ||
| array: &ArrayRef, | ||
| rhs_rows: &[usize], | ||
| equal_to_results: &mut [bool], | ||
| ) { | ||
| assert!( | ||
| !NULLABLE || (array.null_count() == 0 && !self.nulls.might_have_nulls()), | ||
| "called with nullable input" | ||
| ); | ||
| let array_values = array.as_primitive::<T>().values(); | ||
|
|
||
| let iter = izip!( | ||
| lhs_rows.iter(), | ||
| rhs_rows.iter(), | ||
| equal_to_results.iter_mut(), | ||
| ); | ||
|
|
||
| for (&lhs_row, &rhs_row, equal_to_result) in iter { | ||
| let result = { | ||
| // Getting unchecked not only for bound checks but because the bound checks are | ||
| // what prevents auto-vectorization | ||
| let left = if cfg!(debug_assertions) { | ||
| self.group_values[lhs_row] | ||
| } else { | ||
| // SAFETY: indices are guaranteed to be in bounds | ||
| unsafe { *self.group_values.get_unchecked(lhs_row) } | ||
| }; | ||
| let right = if cfg!(debug_assertions) { | ||
| array_values[rhs_row] | ||
| } else { | ||
| // SAFETY: indices are guaranteed to be in bounds | ||
| unsafe { *array_values.get_unchecked(rhs_row) } | ||
| }; | ||
|
|
||
| // Always evaluate, to allow for auto-vectorization | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this makes sense for primitive values -- namely that the cost of checking if we should compare dominated just always comparing |
||
| left.is_eq(right) | ||
| }; | ||
|
|
||
| *equal_to_result = result && *equal_to_result; | ||
| } | ||
| } | ||
|
|
||
| pub fn vectorized_equal_nullable( | ||
| &self, | ||
| lhs_rows: &[usize], | ||
| array: &ArrayRef, | ||
| rhs_rows: &[usize], | ||
| equal_to_results: &mut [bool], | ||
| ) { | ||
| assert!(NULLABLE, "called with non-nullable input"); | ||
| let array = array.as_primitive::<T>(); | ||
|
|
||
| let iter = izip!( | ||
| lhs_rows.iter(), | ||
| rhs_rows.iter(), | ||
| equal_to_results.iter_mut(), | ||
| ); | ||
|
|
||
| for (&lhs_row, &rhs_row, equal_to_result) in iter { | ||
| // Has found not equal to in previous column, don't need to check | ||
| if !*equal_to_result { | ||
| continue; | ||
| } | ||
|
|
||
| // Perf: skip null check (by short circuit) if input is not nullable | ||
| let exist_null = self.nulls.is_null(lhs_row); | ||
| let input_null = array.is_null(rhs_row); | ||
| if let Some(result) = nulls_equal_to(exist_null, input_null) { | ||
| *equal_to_result = result; | ||
| continue; | ||
| } | ||
|
|
||
| // Otherwise, we need to check their values | ||
| *equal_to_result = self.group_values[lhs_row].is_eq(array.value(rhs_row)); | ||
| } | ||
| } | ||
|
Comment on lines
+114
to
+137
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved the code from |
||
| } | ||
|
|
||
| impl<T: ArrowPrimitiveType, const NULLABLE: bool> GroupColumn | ||
|
|
@@ -99,32 +178,15 @@ impl<T: ArrowPrimitiveType, const NULLABLE: bool> GroupColumn | |
| rhs_rows: &[usize], | ||
| equal_to_results: &mut [bool], | ||
| ) { | ||
| let array = array.as_primitive::<T>(); | ||
|
|
||
| let iter = izip!( | ||
| lhs_rows.iter(), | ||
| rhs_rows.iter(), | ||
| equal_to_results.iter_mut(), | ||
| ); | ||
|
|
||
| for (&lhs_row, &rhs_row, equal_to_result) in iter { | ||
| // Has found not equal to in previous column, don't need to check | ||
| if !*equal_to_result { | ||
| continue; | ||
| } | ||
|
|
||
| // Perf: skip null check (by short circuit) if input is not nullable | ||
| if NULLABLE { | ||
| let exist_null = self.nulls.is_null(lhs_row); | ||
| let input_null = array.is_null(rhs_row); | ||
| if let Some(result) = nulls_equal_to(exist_null, input_null) { | ||
| *equal_to_result = result; | ||
| continue; | ||
| } | ||
| // Otherwise, we need to check their values | ||
| } | ||
|
|
||
| *equal_to_result = self.group_values[lhs_row].is_eq(array.value(rhs_row)); | ||
| if !NULLABLE || (array.null_count() == 0 && !self.nulls.might_have_nulls()) { | ||
| self.vectorized_equal_to_non_nullable( | ||
| lhs_rows, | ||
| array, | ||
| rhs_rows, | ||
| equal_to_results, | ||
| ); | ||
| } else { | ||
| self.vectorized_equal_nullable(lhs_rows, array, rhs_rows, equal_to_results); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
As
lhs_rowis not checked here te be in bounds, this method would need to be marked unsafe as well.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.
what do you mean?