perf: improve performance of array_remove, array_remove_n and array_remove_all functions#19996
Merged
comphead merged 7 commits intoapache:mainfrom Jan 26, 2026
Merged
Conversation
comphead
approved these changes
Jan 25, 2026
|
|
||
| fn criterion_benchmark(c: &mut Criterion) { | ||
| // Test array_remove with different data types and array sizes | ||
| bench_array_remove_int64(c); |
Contributor
There was a problem hiding this comment.
great, would be also nice to see performance for nested datatypes, but it can be done in the following PR, for now please mention a TODO here
Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Contributor
Author
|
Thanks for the review. |
de-bgunter
pushed a commit
to de-bgunter/datafusion
that referenced
this pull request
Mar 24, 2026
…ray_remove_all` functions (apache#19996) ## 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 apache#123` indicates that this PR will close issue apache#123. --> - Part of apache/datafusion-comet#2986 ## 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. --> The current implementation of `general_remove` is based on `filter + concat`, which creates intermediate arrays for each list row and can be relatively expensive. This PR introduces an alternative implementation based on `MutableArrayData`, which copies contiguous ranges from the original values buffer directly into the output array. The new approach is semantically equivalent to the existing implementation but reduces intermediate allocations and per-element overhead. ## 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. --> - Replaced `general_remove`'s filter-based implementation with `MutableArrayData` for more efficient memory usage. - Optimized the removal process by adding fast paths for rows where no matching elements need removal. ### Benchmark ``` group after before ----- ----- ------ array_remove_binary/remove/10 1.00 4.6±0.14ms ? ?/sec 2.41 11.0±0.34ms ? ?/sec array_remove_binary/remove/100 1.00 8.5±0.19ms ? ?/sec 1.95 16.6±0.42ms ? ?/sec array_remove_binary/remove/500 1.00 35.9±0.78ms ? ?/sec 1.43 51.4±1.10ms ? ?/sec array_remove_boolean/remove/10 1.00 3.7±0.05ms ? ?/sec 3.23 11.8±0.30ms ? ?/sec array_remove_boolean/remove/100 1.00 8.1±0.15ms ? ?/sec 2.18 17.6±0.35ms ? ?/sec array_remove_boolean/remove/500 1.00 26.6±0.43ms ? ?/sec 1.52 40.3±0.81ms ? ?/sec array_remove_decimal64/remove/10 1.00 3.9±0.07ms ? ?/sec 2.41 9.4±0.18ms ? ?/sec array_remove_decimal64/remove/100 1.00 6.7±0.19ms ? ?/sec 2.12 14.2±0.34ms ? ?/sec array_remove_decimal64/remove/500 1.00 40.3±0.75ms ? ?/sec 1.52 61.1±1.46ms ? ?/sec array_remove_f64/remove/10 1.00 3.8±0.10ms ? ?/sec 1.32 5.0±0.16ms ? ?/sec array_remove_f64/remove/100 1.00 4.8±0.34ms ? ?/sec 1.24 5.9±0.18ms ? ?/sec array_remove_f64/remove/500 1.00 22.3±0.68ms ? ?/sec 1.15 25.5±0.86ms ? ?/sec array_remove_fixed_size_binary/remove/10 1.00 4.7±0.09ms ? ?/sec 1.52 7.2±0.26ms ? ?/sec array_remove_fixed_size_binary/remove/100 1.00 8.0±0.32ms ? ?/sec 1.40 11.1±0.40ms ? ?/sec array_remove_fixed_size_binary/remove/500 1.00 45.4±0.97ms ? ?/sec 1.16 52.6±1.43ms ? ?/sec array_remove_int64/remove/10 1.00 3.9±0.11ms ? ?/sec 2.24 8.8±0.24ms ? ?/sec array_remove_int64/remove/100 1.00 5.5±0.18ms ? ?/sec 2.32 12.8±0.44ms ? ?/sec array_remove_int64/remove/500 1.00 25.5±1.06ms ? ?/sec 1.61 40.9±1.25ms ? ?/sec array_remove_strings/remove/10 1.00 4.5±0.10ms ? ?/sec 2.41 10.9±0.28ms ? ?/sec array_remove_strings/remove/100 1.00 8.5±0.37ms ? ?/sec 2.00 17.0±0.71ms ? ?/sec array_remove_strings/remove/500 1.00 35.9±0.84ms ? ?/sec 1.48 53.1±1.91ms ? ?/sec ``` ## Are these changes tested? Yes. Existing SLT for `array` continue to pass without modification. Benchmarks were added. <!-- 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)? --> ## Are there any user-facing changes? No. <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Oleks V <comphead@users.noreply.github.com>
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
The current implementation of
general_removeis based onfilter + concat, which creates intermediate arrays for each list row and can be relatively expensive.This PR introduces an alternative implementation based on
MutableArrayData, which copies contiguous ranges from the original values buffer directly into the output array. The new approach is semantically equivalent to the existing implementation but reduces intermediate allocations and per-element overhead.What changes are included in this PR?
general_remove's filter-based implementation withMutableArrayDatafor more efficient memory usage.Benchmark
Are these changes tested?
Yes. Existing SLT for
arraycontinue to pass without modification. Benchmarks were added.Are there any user-facing changes?
No.