neilconway opened a new pull request, #26062: URL: https://github.com/apache/datafusion/pull/26062
## 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 #. ## Rationale for this change #22308 changed `sqrt` so that it raises an error on negative floating point inputs. In the course of doing that, it changed all of the unary math UDFs to use `try_unary` instead of `unary`. Switching to `try_unary` regressed the performance of those UDFs. The effect was the most extreme for `sqrt`, because #22308 also added a per-value check that inhibited vectorization, but the other UDFs also suffered from `try_unary`'s additional overhead. This PR preserves the error-handling change in #22308 but implements it in a different way: we add support for an optional "input check" function to the unary math macro. If supplied, the check function is applied to every input value (including null slot) in a branch-free loop, which doesn't inhibit vectorization. If that loop detects an erroneous input, we do a second branching loop to find the problematic value to report the error. Finally, math UDFs that don't need the error check can go back to using `unary`. Benchmarks: (x86, AMD EPYC Milan): - sqrt/f64: 32.3µs → 9.7µs, −70% - sqrt/f32: 27.6µs → 3.0µs, −89% - sqrt/f64 with nulls: 34.0µs → 9.8µs, −71% - sqrt/f32 with nulls: 30.8µs → 3.0µs, −90% - degrees/f64: 1.90µs → 1.32µs, −30% - degrees/f32: 1.05µs → 0.76µs, −27% - degrees/f64 with nulls: 5.1µs → 1.33µs, −74% - degrees/f32 with nulls: 4.5µs → 0.77µs, −83% ## What changes are included in this PR? See above. Also added a benchmark for `sqrt` and `degrees` (`degrees` is a trivial math UDF like that effectively measures the dispatch overhead). Other, more expensive math UDFs still got slower but their relative slowdown was much less. ## What is the testing strategy for this PR? Existing tests pass; added new unit test for new error-check facility. ## Are there any user-facing changes? No. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
