Skip to content
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

Speed up checked kernels for non-null data (~1.4-5x faster) #2749

Merged
merged 3 commits into from
Sep 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 8 additions & 11 deletions arrow/src/compute/kernels/arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,19 +292,16 @@ where
.map(|x| len - x.count_set_bits())
.unwrap_or_default();

let mut buffer = BufferBuilder::<O::Native>::new(len);
buffer.append_n_zeroed(len);
let slice = buffer.as_slice_mut();
let values = a.values().iter().zip(b.values()).map(|(l, r)| op(*l, *r));

try_for_each_valid_idx(len, 0, null_count, null_buffer.as_deref(), |idx| {
Dandandan marked this conversation as resolved.
Show resolved Hide resolved
unsafe {
*slice.get_unchecked_mut(idx) =
op(a.value_unchecked(idx), b.value_unchecked(idx))?
};
Ok::<_, ArrowError>(())
})?;
// JUSTIFICATION
// Benefit
// ~60% speedup
// Soundness
// `values` is an iterator with a known size from a PrimitiveArray
let buffer = unsafe { Buffer::try_from_trusted_len_iter(values) }?;

Ok(unsafe { build_primitive_array(len, buffer.finish(), null_count, null_buffer) })
Ok(unsafe { build_primitive_array(len, buffer, null_count, null_buffer) })
}

/// Applies the provided binary operation across `a` and `b`, collecting the optional results
Expand Down