perf: Optimize array_positions() for scalar needle#20770
Open
neilconway wants to merge 4 commits intoapache:mainfrom
Open
perf: Optimize array_positions() for scalar needle#20770neilconway wants to merge 4 commits intoapache:mainfrom
array_positions() for scalar needle#20770neilconway wants to merge 4 commits intoapache:mainfrom
Conversation
Contributor
Author
|
Benchmarks: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
array_positionspreviously compared the needle against each row's sub-array individually. When the needle is a scalar (the common case), we can do a single bulkarrow_ord::cmp::not_distinctcomparison against the entire flat values buffer and then walk the result bitmap, which is significantly faster: the speedup on thearray_positions()microbenchmarks ranges from 5x to 40x, depending on the size of the array.The same pattern has already been applied to
array_position(#20532), and previously to other array UDFs.What changes are included in this PR?
array_positions.array_position's existing fast path slightly for consistencyarray_positionswith sliced ListArrays, for peace of mindarray_positionsfast path.Are these changes tested?
Yes.
Are there any user-facing changes?
No.
AI usage
Multiple AI tools were used to iterate on this PR. I have reviewed and understand the resulting code.