You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "neilconway (via GitHub)" <gi...@apache.org> on 2026/02/28 19:28:22 UTC
[PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
neilconway opened a new pull request, #20623:
URL: https://github.com/apache/datafusion/pull/20623
## Which issue does this PR close?
- Closes #20622.
## Rationale for this change
Several array set operations (e.g., `array_distinct`, `array_union`, `array_intersect`, `array_except`) have this property:
* Convert the input(s) using RowConverter, ideally in bulk
* Apply the set operation as appropriate, which adds or removes elements from the set of `Rows`
* Convert the final set of `Rows` back into `ArrayRef`
However, we can do a little better for the final step: instead of converting from `Rows` back into `ArrayRef`, we can just track which indices in the input(s) correspond to the values we want to return. We can then grab those values with a single `take`, which avoids the Row-to-Arrayref deserialization overhead. This is a 5-20% performance win, depending on the set operation and the characteristics of the input.
The only wrinkle is that for `intersect` and `union`, because there are multiple inputs we need to concatenate the inputs together so that we have a single index space. It turns out that this optimization is a win, even incurring the `concat` overhead.
## What changes are included in this PR?
* Add a benchmark for `array_except`
* Implement this optimization for `array_distinct`, `array_union`, `array_intersect`, `array_except`
## Are these changes tested?
Yes, and benchmarked.
## 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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #20623:
URL: https://github.com/apache/datafusion/pull/20623
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb-ghbot (via GitHub)" <gi...@apache.org>.
alamb-ghbot commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-4005506811
๐ค: Benchmark completed
<details><summary>Details</summary>
<p>
```
group main neilc_optimize-array-take-results
----- ---- ---------------------------------
array_distinct/high_duplicate/10 1.04 208.7ยฑ2.62ยตs ? ?/sec 1.00 201.4ยฑ6.79ยตs ? ?/sec
array_distinct/high_duplicate/100 1.15 1539.4ยฑ21.62ยตs ? ?/sec 1.00 1336.1ยฑ19.58ยตs ? ?/sec
array_distinct/high_duplicate/50 1.13 785.0ยฑ8.15ยตs ? ?/sec 1.00 693.2ยฑ4.46ยตs ? ?/sec
array_distinct/low_duplicate/10 1.23 265.1ยฑ9.41ยตs ? ?/sec 1.00 215.6ยฑ9.73ยตs ? ?/sec
array_distinct/low_duplicate/100 1.40 2.1ยฑ0.02ms ? ?/sec 1.00 1486.8ยฑ14.11ยตs ? ?/sec
array_distinct/low_duplicate/50 1.37 1076.8ยฑ13.15ยตs ? ?/sec 1.00 784.0ยฑ22.61ยตs ? ?/sec
array_except/high_overlap/10 1.00 347.5ยฑ1.83ยตs ? ?/sec
array_except/high_overlap/100 1.00 2.9ยฑ0.01ms ? ?/sec
array_except/high_overlap/50 1.00 1469.5ยฑ6.23ยตs ? ?/sec
array_except/low_overlap/10 1.00 377.2ยฑ10.05ยตs ? ?/sec
array_except/low_overlap/100 1.00 3.1ยฑ0.01ms ? ?/sec
array_except/low_overlap/50 1.00 1584.8ยฑ9.89ยตs ? ?/sec
array_intersect/high_overlap/10 1.13 478.4ยฑ5.45ยตs ? ?/sec 1.00 422.6ยฑ6.28ยตs ? ?/sec
array_intersect/high_overlap/100 1.12 4.2ยฑ0.14ms ? ?/sec 1.00 3.7ยฑ0.01ms ? ?/sec
array_intersect/high_overlap/50 1.12 2.1ยฑ0.05ms ? ?/sec 1.00 1872.7ยฑ16.28ยตs ? ?/sec
array_intersect/low_overlap/10 1.03 370.1ยฑ3.90ยตs ? ?/sec 1.00 359.0ยฑ6.67ยตs ? ?/sec
array_intersect/low_overlap/100 1.02 3.4ยฑ0.05ms ? ?/sec 1.00 3.3ยฑ0.02ms ? ?/sec
array_intersect/low_overlap/50 1.02 1678.6ยฑ10.20ยตs ? ?/sec 1.00 1644.4ยฑ25.66ยตs ? ?/sec
array_union/high_overlap/10 1.22 453.9ยฑ2.77ยตs ? ?/sec 1.00 372.6ยฑ11.26ยตs ? ?/sec
array_union/high_overlap/100 2.04 6.5ยฑ0.22ms ? ?/sec 1.00 3.2ยฑ0.07ms ? ?/sec
array_union/high_overlap/50 1.22 1955.1ยฑ13.91ยตs ? ?/sec 1.00 1598.4ยฑ30.60ยตs ? ?/sec
array_union/low_overlap/10 1.38 524.3ยฑ6.77ยตs ? ?/sec 1.00 379.7ยฑ7.33ยตs ? ?/sec
array_union/low_overlap/100 2.25 8.0ยฑ0.14ms ? ?/sec 1.00 3.6ยฑ0.03ms ? ?/sec
array_union/low_overlap/50 1.38 2.5ยฑ0.03ms ? ?/sec 1.00 1823.0ยฑ21.32ยตs ? ?/sec
```
</p>
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-4032688317
Thanks @neilconway and @Jefffrey
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-4005547562
Those are some pretty nice benchmark results โค๏ธ ๐
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-3977630417
Benchmarks:
```
array_union:
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโ
โ Scenario โ Before โ After โ Change โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/10 โ 237 ยตs โ 208 ยตs โ -12.3% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/50 โ 1.06 ms โ 886 ยตs โ -16.3% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/100 โ 2.02 ms โ 1.70 ms โ -16.1% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/10 โ 269 ยตs โ 224 ยตs โ -18.0% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/50 โ 1.24 ms โ 1.00 ms โ -20.9% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/100 โ 2.18 ms โ 1.73 ms โ -19.6% โ
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโ
array_intersect:
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโ
โ Scenario โ Before โ After โ Change โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/10 โ 216 ยตs โ 199 ยตs โ -8.3% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/50 โ 1.11 ms โ 1.01 ms โ -8.4% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ high_overlap/100 โ 2.18 ms โ 1.99 ms โ -8.6% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/10 โ 176 ยตs โ 174 ยตs โ -1.6% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/50 โ 1.01 ms โ 997 ยตs โ -1.4% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโค
โ low_overlap/100 โ 2.02 ms โ 2.00 ms โ -0.7% โ
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโ
array_except:
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Scenario โ Before โ After โ Change โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ high_overlap/10 โ 218 ยตs โ 212 ยตs โ -3.4% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ high_overlap/50 โ 908 ยตs โ 874 ยตs โ -1.5% (not significant) โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ high_overlap/100 โ 1.74 ms โ 1.68 ms โ -2.9% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ low_overlap/10 โ 250 ยตs โ 231 ยตs โ -8.1% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ low_overlap/50 โ 1.12 ms โ 1.00 ms โ -11.2% โ
โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ low_overlap/100 โ 2.01 ms โ 1.75 ms โ -11.7% โ
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโ
array_distinct:
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโ
โ Scenario โ Before โ After โ Change โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ high_duplicate/10 โ 69.3 ยตs โ 65.6 ยตs โ -8.2% โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ high_duplicate/50 โ 350.0 ยตs โ 322.2 ยตs โ -8.9% โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ high_duplicate/100 โ 671.4 ยตs โ 624.8 ยตs โ -7.2% โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ low_duplicate/10 โ 106.8 ยตs โ 91.2 ยตs โ -15.0% โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ low_duplicate/50 โ 526.3 ยตs โ 434.3 ยตs โ -18.1% โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโค
โ low_duplicate/100 โ 975.7 ยตs โ 767.3 ยตs โ -21.4% โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโ
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb-ghbot (via GitHub)" <gi...@apache.org>.
alamb-ghbot commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-4005416196
๐ค `./gh_compare_branch_bench.sh` [compare_branch_bench.sh](https://github.com/alamb/datafusion-benchmarking/blob/main/scripts/compare_branch_bench.sh) Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing neilc/optimize-array-take-results (f5a119e905985d608b38a2fccf46b0027e991791) to 8df75c3f043722f989e1936566543595f02801aa [diff](https://github.com/apache/datafusion/compare/8df75c3f043722f989e1936566543595f02801aa..f5a119e905985d608b38a2fccf46b0027e991791)
BENCH_NAME=array_set_ops
BENCH_COMMAND=cargo bench --features=parquet --bench array_set_ops
BENCH_FILTER=
BENCH_BRANCH_NAME=neilc_optimize-array-take-results
Results will be posted here when complete
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] perf: Optimize set operations to avoid RowConverter deserialization overhead [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #20623:
URL: https://github.com/apache/datafusion/pull/20623#issuecomment-4005415279
run benchmark array_set_ops
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org