This is an automated email from the ASF dual-hosted git repository.
alamb 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 601be25e63 perf: Avoid ArrayData allocation in
PrimitiveArray::reinterpret_cast (#9129)
601be25e63 is described below
commit 601be25e63933bbcd8e428fc4cfa6b0de3161045
Author: Andrew Lamb <[email protected]>
AuthorDate: Sun Jan 11 07:25:58 2026 -0500
perf: Avoid ArrayData allocation in PrimitiveArray::reinterpret_cast (#9129)
# Which issue does this PR close?
- part of https://github.com/apache/arrow-rs/issues/9128
# Rationale for this change
While studying / profiling the Parquet reader I have noticed several
places where unecessary allocations are happening
# What changes are included in this PR?
Avoid ArrayData allocation in `PrimitiveArray::reinterpret_cast`
# Are these changes tested?
<!--
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)?
-->
# Are there any user-facing changes?
<!--
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.
-->
---------
Co-authored-by: Jeffrey Vo <[email protected]>
---
arrow-array/src/array/primitive_array.rs | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/arrow-array/src/array/primitive_array.rs
b/arrow-array/src/array/primitive_array.rs
index 457c242814..87de5f6160 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -859,11 +859,7 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
where
K: ArrowPrimitiveType<Native = T::Native>,
{
- let d = self.to_data().into_builder().data_type(K::DATA_TYPE);
-
- // SAFETY:
- // Native type is the same
- PrimitiveArray::from(unsafe { d.build_unchecked() })
+ PrimitiveArray::new(self.values.clone(), self.nulls.clone())
}
/// Applies a unary infallible function to a primitive array, producing a