-
Notifications
You must be signed in to change notification settings - Fork 1.9k
perf: Optimize contains for scalar search arg
#19514
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
Conversation
comphead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andygrove the numbers make huge sense to me, what prob concerns is DF using make_scalar_function in lots of places so the same problem can be relevant for others.
Would you mind adding more details what is the exact reason and what scalar/array combinations are the most trouble?
this info might be important how DF treats bultin functions now
Basically, the The three implementations of
|
The issue is that It would perhaps be better if it accepted |
## 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 <!-- 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. --> This PR is an alternative to #19514 that replaces the use of `make_scalar_function` with a new `make_scalar_function_columnar` that avoids expanding scalar values to arrays for each batch. | Benchmark | Old Code | New Code | Improvement | |--------------------------------------------|----------|----------|-------------| | contains_StringViewArray_scalar_strlen_8 | ~97 µs | ~34 µs | 2.8x faster | | contains_StringViewArray_scalar_strlen_32 | ~175 µs | ~37 µs | 4.7x faster | | contains_StringViewArray_scalar_strlen_128 | ~332 µs | ~42 µs | 7.9x faster | | contains_StringViewArray_scalar_strlen_512 | ~371 µs | ~88 µs | 4.2x faster | ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Existing tests ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
Which issue does this PR close?
Rationale for this change
ContainsFuncusedmake_scalar_function, which expands scalar arguments into arrays before calling Arrow'scontainsfunction, bypassing Arrow's built-in scalar optimization.After optimizing for the scalar search case, performance is much better:
What changes are included in this PR?
Rewrote invoke_with_args to:
Are these changes tested?
Are there any user-facing changes?