This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 062ce4356d perf: speed up `FixedSizeBinary` `filter` kernel (#10993)
062ce4356d is described below
commit 062ce4356d2b404295cf47dc5023a5f22179c7ad
Author: RIchard Baah <[email protected]>
AuthorDate: Sun Sep 6 00:48:48 2026 -0400
perf: speed up `FixedSizeBinary` `filter` kernel (#10993)
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax.
-->
- Closes none.
# Rationale for this change
`filter_fixed_size_binary` used `MutableBuffer::new` which
zero-initializes
the buffer before immediately overwriting every byte. This skips that.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
Adds `copy_fsb_indices` helper used by the `IndexIterator` and `Indices`
paths in `filter_fixed_size_binary`. Swaps `MutableBuffer::new` +
`extend_from_slice` for `with_capacity` + `ptr::copy_nonoverlapping`.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
# Are these changes tested?
yes, existing test.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
If this PR claims a performance improvement, please include evidence
such as benchmark results.
-->
# Are there any user-facing changes?
no
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
-->
---
arrow-select/src/filter.rs | 61 ++++++++++++++++++++++++++++++++--------------
1 file changed, 43 insertions(+), 18 deletions(-)
diff --git a/arrow-select/src/filter.rs b/arrow-select/src/filter.rs
index 586b6e6ba7..85b21df03c 100644
--- a/arrow-select/src/filter.rs
+++ b/arrow-select/src/filter.rs
@@ -943,6 +943,37 @@ fn filter_byte_view<T: ByteViewType>(
unsafe { GenericByteViewArray::new_unchecked(views, buffers, nulls) }
}
+/// Copies fixed-size binary elements at `indices` from `values` into a new
`MutableBuffer`.
+/// Uses raw pointer writes and `with_capacity` to avoid zero-initialization
and per-call overhead.
+#[inline(always)]
+fn copy_fsb_indices(
+ values: &[u8],
+ value_length: usize,
+ indices: impl Iterator<Item = usize>,
+ count: usize,
+) -> MutableBuffer {
+ let total = count * value_length;
+ let mut buffer = MutableBuffer::with_capacity(total);
+ let dst_base = buffer.as_mut_ptr();
+ let mut write_offset = 0usize;
+ for idx in indices {
+ let src_start = idx * value_length;
+ // SAFETY: `idx` is derived from the filter predicate so it is a valid
array index;
+ // we allocated `count * value_length` bytes and advance by
`value_length` per step.
+ unsafe {
+ std::ptr::copy_nonoverlapping(
+ values.as_ptr().add(src_start),
+ dst_base.add(write_offset),
+ value_length,
+ );
+ }
+ write_offset += value_length;
+ }
+ // SAFETY: we wrote exactly `count * value_length` bytes into the buffer.
+ unsafe { buffer.set_len(total) };
+ buffer
+}
+
fn filter_fixed_size_binary(
array: &FixedSizeBinaryArray,
predicate: &FilterPredicate,
@@ -969,24 +1000,18 @@ fn filter_fixed_size_binary(
}
buffer
}
- IterationStrategy::IndexIterator => {
- let iter = IndexIterator::new(&predicate.filter,
predicate.count).map(|x| {
-
&values[calculate_offset_from_index(x)..calculate_offset_from_index(x + 1)]
- });
-
- let mut buffer = MutableBuffer::new(predicate.count *
value_length);
- iter.for_each(|item| buffer.extend_from_slice(item));
- buffer
- }
- IterationStrategy::Indices(indices) => {
- let iter = indices.iter().map(|x| {
-
&values[calculate_offset_from_index(*x)..calculate_offset_from_index(*x + 1)]
- });
-
- let mut buffer = MutableBuffer::new(predicate.count *
value_length);
- iter.for_each(|item| buffer.extend_from_slice(item));
- buffer
- }
+ IterationStrategy::IndexIterator => copy_fsb_indices(
+ values,
+ value_length,
+ IndexIterator::new(&predicate.filter, predicate.count),
+ predicate.count,
+ ),
+ IterationStrategy::Indices(indices) => copy_fsb_indices(
+ values,
+ value_length,
+ indices.iter().copied(),
+ predicate.count,
+ ),
IterationStrategy::All | IterationStrategy::None => unreachable!(),
};