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

   # Which issue does this PR close?
   
   - N/A
   
   # Rationale for this change
   
   `cast_numeric_arrays` performed a cast between two numeric types using 
either `unary_opt` (in safe mode) or `try_unary` (in not-safe mode). However, 
both kernels are considerably slower than `unary`: they don't vectorize as 
well, and `unary_opt` also needs to allocate a null buffer.
   
   For many common pairs of numeric types, casting is infallible, and therefore 
the additional overhead of using `unary_opt` / `try_unary` is unnecessary.
   
   Benchmarks: (M4 Max)
   
     - cast int32 to int64 512: 344.130 → 84.676 ns, −75.4%
     - cast int32 to float32 512: 332.420 → 64.278 ns, −80.7%
     - cast int32 to float64 512: 372.920 → 87.124 ns, −76.6%
     - cast float64 to float32 512: 345.900 → 70.852 ns, −79.5%
     - cast int32 to uint32 512: 564.230 → 540.660 ns, −4.2%
     - cast int64 to int32 512: 655.640 → 635.060 ns, −3.1%
   
   # What changes are included in this PR?
   
   * Add `is_infallible_numeric_cast`, a compile-time predicate on pairs of 
types to determine if a cast between them is fallible.
   * Use `unary` for infallible numeric casts
   * Refactor `cast_numeric_arrays` to get rid of two unnecessary helpers 
(`try_numeric_cast`, `numeric_cast`), so that the reader can see all of the 
numeric cast logic in a single place
   * Add unit test
   
   # Are these changes tested?
   
   Yes; existing tests pass, new test added.
   
   # Are there any user-facing changes?
   
   No. The fast-path still uses the same underlying typecast code, the change 
here is just in the machinery that invokes it.
   


-- 
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