RTEnzyme opened a new issue, #5297:
URL: https://github.com/apache/arrow-rs/issues/5297

   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   <!--
   A clear and concise description of what the problem is. Ex. I'm always 
frustrated when [...] 
   (This section helps Arrow developers understand the context and *why* for 
this feature, in addition to  the *what*)
   -->
   From issue in arrow-datafusion: 
https://github.com/apache/arrow-datafusion/issues/8816#issue-2074225073
   
   For the below code: 
https://github.com/apache/arrow-datafusion/blob/e5ba6de074affd40cb0984d503694e543d816a6c/datafusion/physical-expr/src/expressions/case.rs#L164C1-L165C1
   ```Rust
   remainder = and(&remainder, &not(&when_match)?)?;
   ```
   
   By implementing the and_not boolean function, we can fuse these two 
operations into one single operation, instead of performing them separately 
(first applying not to when_match and then applying and to remainder). This 
optimization has the potential to enhance the efficiency of the code for the 
following reasons:
   - The and_not function is natively implemented in x86 as ANDN, which merges 
the two operations into a single instruction.
   - By performing these operations in a single iteration instead of two, we 
can avoid materializing an extra intermediate array.
   
   **Describe the solution you'd like**
   <!--
   A clear and concise description of what you want to happen.
   -->
   We can implement `and_not` in 
[boolean](https://github.com/apache/arrow-rs/blob/master/arrow-arith/src/boolean.rs)
 and 
[bitwise](https://github.com/apache/arrow-rs/blob/master/arrow-arith/src/bitwise.rs).
   
   
   **Describe alternatives you've considered**
   <!--
   A clear and concise description of any alternative solutions or features 
you've considered.
   -->
   
   **Additional context**
   <!--
   Add any other context or screenshots about the feature request here.
   -->
   I conduct a 
[benchmark](https://github.com/apache/arrow-datafusion/issues/8816#issuecomment-1886252573)
 to show the improvement:
   
   | array_length | and(lhs, not(rhs)) | and_not(lhs, rhs) | Improvement Ratio|
   |--------------|-------------------|------------------|------------------|
   | 100 | 149.17 ns | 102.88 ns | 31.11% |
   | 1000 | 167.16 ns | 78.770 ns | 52.89% |
   | 10000 | 270.81 ns | 90.285 ns | 66.67% |
   | 100000 | 666.20 ns | 336.37 ns | 49.51% |
   
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to