You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/14 08:02:01 UTC

[GitHub] [arrow-rs] jhorstmann opened a new pull request, #2064: Support nullable indices in boolean take kernel and some optimizations

jhorstmann opened a new pull request, #2064:
URL: https://github.com/apache/arrow-rs/pull/2064

   # 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. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #2057.
   
   # Rationale for this change
    
    <!---
    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?
   
    - Use the `PrimitiveIter` to iterate over indices, which makes it easier to handle nullable indices.
    - Split up the kernel into separate logic for taking the values and the validity bitmap. This reduces branching in the inner loop and thus increases the performance.
   
   # Are there any user-facing changes?
   
   no
   
   # Benchmark results compared to master
   
   ```
   Gnuplot not found, using plotters backend
   take bool 512           time:   [1.3921 us 1.3927 us 1.3933 us]                           
                           change: [+3.7963% +3.9074% +3.9940%] (p = 0.00 < 0.05)
                           Performance has regressed.
   
   take bool 1024          time:   [3.6781 us 3.8022 us 3.9126 us]                            
                           change: [-33.173% -31.574% -30.047%] (p = 0.00 < 0.05)
                           Performance has improved.
   
   take bool 4096          time:   [10.833 us 10.878 us 10.924 us]                            
                           change: [-67.171% -67.042% -66.917%] (p = 0.00 < 0.05)
                           Performance has improved.
   
   take bool nulls 512     time:   [1.4058 us 1.4067 us 1.4077 us]                                 
                           change: [+4.1519% +4.3855% +4.6259%] (p = 0.00 < 0.05)
                           Performance has regressed.
   
   take bool nulls 1024    time:   [2.5999 us 2.6011 us 2.6027 us]                                  
                           change: [-31.505% -31.418% -31.333%] (p = 0.00 < 0.05)
                           Performance has improved.
   
   take bool nulls 4096    time:   [9.7339 us 9.7377 us 9.7420 us]                                  
                           change: [-54.586% -54.558% -54.531%] (p = 0.00 < 0.05)
                           Performance has improved.
   ```
   
   There is a small regression for very small inputs, which will probably be alleviated by #1857. Larger inputs see a big improvement.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] ursabot commented on pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064#issuecomment-1186201927

   Benchmark runs are scheduled for baseline = 72dada6d656e88f0d07efa2cc32ea9670d061fc2 and contender = a6379fe9818de3133a80700b7b8d6d9d59b29e37. a6379fe9818de3133a80700b7b8d6d9d59b29e37 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/2727874daea445068ec29ca65620e641...791f639a7f6e42f3a4ffb9a10939fe46/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/fb6d5548a0694b5cb6c62947edd428c4...aff4676a89cb43f4868ddff42f5d433a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/0c6195c7776a4ab8a142125cb6f3eb0d...aacdb4e67f464781a62e585860ef3474/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/423766dcd96b490eae3b46de31ccb567...c1e4b6fc30e84c178f6a5c1b7378555a/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064#discussion_r922269054


##########
arrow/src/compute/kernels/take.rs:
##########
@@ -599,76 +599,68 @@ where
     Ok(PrimitiveArray::<T>::from(data))
 }
 
-/// `take` implementation for boolean arrays
-fn take_boolean<IndexType>(
-    values: &BooleanArray,
+fn take_bits<IndexType>(
+    values: &Buffer,
+    values_offset: usize,
     indices: &PrimitiveArray<IndexType>,
-) -> Result<BooleanArray>
+) -> Result<Buffer>
 where
     IndexType: ArrowNumericType,
     IndexType::Native: ToPrimitive,
 {
-    let data_len = indices.len();
+    let len = indices.len();
+    let values_slice = values.as_slice();
+    let mut output_buffer = MutableBuffer::new_null(len);
+    let output_slice = output_buffer.as_slice_mut();
 
-    let num_byte = bit_util::ceil(data_len, 8);
-    let mut val_buf = MutableBuffer::from_len_zeroed(num_byte);
-
-    let val_slice = val_buf.as_slice_mut();
-
-    let null_count = values.null_count();
-
-    let nulls = if null_count == 0 {
-        (0..data_len).try_for_each::<_, Result<()>>(|i| {
-            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
-                ArrowError::ComputeError("Cast to usize failed".to_string())
-            })?;
+    indices

Review Comment:
   This seems to lose the special case of no null values, I would have naively thought this would make a non-trivial performance difference for the very common case where there aren't any nulls?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] jhorstmann commented on a diff in pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
jhorstmann commented on code in PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064#discussion_r922281295


##########
arrow/src/compute/kernels/take.rs:
##########
@@ -599,76 +599,68 @@ where
     Ok(PrimitiveArray::<T>::from(data))
 }
 
-/// `take` implementation for boolean arrays
-fn take_boolean<IndexType>(
-    values: &BooleanArray,
+fn take_bits<IndexType>(
+    values: &Buffer,
+    values_offset: usize,
     indices: &PrimitiveArray<IndexType>,
-) -> Result<BooleanArray>
+) -> Result<Buffer>
 where
     IndexType: ArrowNumericType,
     IndexType::Native: ToPrimitive,
 {
-    let data_len = indices.len();
+    let len = indices.len();
+    let values_slice = values.as_slice();
+    let mut output_buffer = MutableBuffer::new_null(len);
+    let output_slice = output_buffer.as_slice_mut();
 
-    let num_byte = bit_util::ceil(data_len, 8);
-    let mut val_buf = MutableBuffer::from_len_zeroed(num_byte);
-
-    let val_slice = val_buf.as_slice_mut();
-
-    let null_count = values.null_count();
-
-    let nulls = if null_count == 0 {
-        (0..data_len).try_for_each::<_, Result<()>>(|i| {
-            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
-                ArrowError::ComputeError("Cast to usize failed".to_string())
-            })?;
+    indices

Review Comment:
   I was also a bit surprised, we are probably trading the bounds check for `indices.value(i)`, which is avoided by the iterator, vs. the added null check. I can try adding another variant without nulls and benchmark that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064#discussion_r922422377


##########
arrow/src/compute/kernels/take.rs:
##########
@@ -599,76 +599,68 @@ where
     Ok(PrimitiveArray::<T>::from(data))
 }
 
-/// `take` implementation for boolean arrays
-fn take_boolean<IndexType>(
-    values: &BooleanArray,
+fn take_bits<IndexType>(
+    values: &Buffer,
+    values_offset: usize,
     indices: &PrimitiveArray<IndexType>,
-) -> Result<BooleanArray>
+) -> Result<Buffer>
 where
     IndexType: ArrowNumericType,
     IndexType::Native: ToPrimitive,
 {
-    let data_len = indices.len();
+    let len = indices.len();
+    let values_slice = values.as_slice();
+    let mut output_buffer = MutableBuffer::new_null(len);
+    let output_slice = output_buffer.as_slice_mut();
 
-    let num_byte = bit_util::ceil(data_len, 8);
-    let mut val_buf = MutableBuffer::from_len_zeroed(num_byte);
-
-    let val_slice = val_buf.as_slice_mut();
-
-    let null_count = values.null_count();
-
-    let nulls = if null_count == 0 {
-        (0..data_len).try_for_each::<_, Result<()>>(|i| {
-            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
-                ArrowError::ComputeError("Cast to usize failed".to_string())
-            })?;
+    indices

Review Comment:
   Yeah, I basically wonder if it isn't showing up as a regression as separating out the null mask handling makes up for it. However, perhaps we can make it even faster by adding the special case back :smile: 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] jhorstmann commented on a diff in pull request #2064: Support nullable indices in boolean take kernel and some optimizations

Posted by GitBox <gi...@apache.org>.
jhorstmann commented on code in PR #2064:
URL: https://github.com/apache/arrow-rs/pull/2064#discussion_r922568903


##########
arrow/src/compute/kernels/take.rs:
##########
@@ -599,76 +599,68 @@ where
     Ok(PrimitiveArray::<T>::from(data))
 }
 
-/// `take` implementation for boolean arrays
-fn take_boolean<IndexType>(
-    values: &BooleanArray,
+fn take_bits<IndexType>(
+    values: &Buffer,
+    values_offset: usize,
     indices: &PrimitiveArray<IndexType>,
-) -> Result<BooleanArray>
+) -> Result<Buffer>
 where
     IndexType: ArrowNumericType,
     IndexType::Native: ToPrimitive,
 {
-    let data_len = indices.len();
+    let len = indices.len();
+    let values_slice = values.as_slice();
+    let mut output_buffer = MutableBuffer::new_null(len);
+    let output_slice = output_buffer.as_slice_mut();
 
-    let num_byte = bit_util::ceil(data_len, 8);
-    let mut val_buf = MutableBuffer::from_len_zeroed(num_byte);
-
-    let val_slice = val_buf.as_slice_mut();
-
-    let null_count = values.null_count();
-
-    let nulls = if null_count == 0 {
-        (0..data_len).try_for_each::<_, Result<()>>(|i| {
-            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
-                ArrowError::ComputeError("Cast to usize failed".to_string())
-            })?;
+    indices

Review Comment:
   I'm planning to look at iteration in general in #1857 and ideally convince the compiler to do the specialization itself.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org