You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "0lai0 (via GitHub)" <gi...@apache.org> on 2026/08/03 15:18:01 UTC
[PR] perf: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
0lai0 opened a new pull request, #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233
## 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 #5099
## 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.
-->
`spark_size` reimplemented List/LargeList/FixedSizeList sizing with a per-row builder loop that duplicates Arrow's `length` kernel.
Reuse the kernel and apply Spark's null to `-1` semantics afterward
## 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.
-->
- List / LargeList / FixedSizeList: use `arrow::compute::kernels::length::length`
- LargeList Int64 to Int32 via `cast_with_options(safe: false)` so overflow errors instead of becoming `-1`
- Null to `-1` by patching the values buffer (avoid `zip` / `MutableArrayData`, which regressed ~2x)
- Scalar path: read `value_length` instead of `value(0).len()`
- Map unchanged (`length` does not support MapArray)
- Docs: size entry in array_funcs audit + optimizing_expressions table
### Benchmark (`array_size`, 8192 rows, ~10% nulls)
| shape | before | after | change |
|-------|--------|-------|--------|
| list of short arrays | 7.53 µs | 3.36 µs | −55.7% (~2.2x) |
| list of long arrays | 7.65 µs | 3.30 µs | −55.8% (~2.3x) |
## How 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 `size` unit tests plus a new no-null List case covering the `null_count == 0` fast path
--
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: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233#issuecomment-5187469483
Open a issue #5266, kept out of #5233 because the technique is different (offset-buffer windowing, not the length kernel) and needs its own benchmark. I’ll fix it as soon as possible.
--
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: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233#issuecomment-5192606658
Thanks for the revisions. Every item from the last round is addressed, and the benchmark story is much better now that the no-null shape is in.
I ran the checks locally on `e28ea8c`:
- `cargo test -p datafusion-comet-spark-expr size`, 11 passed
- `cargo clippy -p datafusion-comet-spark-expr --all-targets -- -D warnings`, clean
- `cargo bench --bench array_size`
The benchmark numbers reproduce on my machine, against the `main` numbers I measured last time:
| shape | main | this PR | change |
| --- | --- | --- | --- |
| list of short arrays (10% null) | 9.30 µs | 1.63 µs | 5.7x |
| list of long arrays (10% null) | 9.93 µs | 1.61 µs | 6.2x |
| list, no nulls | 6.67 µs | 0.56 µs | 12x |
| LargeList (10% null) | 9.70 µs | 7.54 µs | 1.3x |
I also went back through the two things that worried me about moving to buffer-level ops, and both hold. I read the `length` kernel in `arrow-string` 58.4.0 to confirm it covers all three types the dispatch now routes to it, and that `FixedSizeList` carries the input null buffer through. The `set_indices` patch is offset-correct because `Not` on a `&BooleanBuffer` rebuilds at offset 0 with the sliced length, which is exactly what `test_spark_size_sliced_list_array` pins. And the `safe: false` cast on the `LargeList` path visits null slots too, but a null list row's offsets still give a small in-range length, so it cannot raise a spurious overflow.
Two things I would like to see before merge.
**A tracking issue for the `LargeList` path.** Thanks for opening #5266 for Map. `LargeList` still needs one. It is at 1.3x while `List` gets 12x, and the reason is visible in the code: the kernel allocates an Int64 array, `cast_with_options` allocates a second, and `to_vec` allocates a third. Building Int32 straight from the offsets would close that. I do not want this to hold the PR up, but without an issue it will not get picked up.
**The comment at `size.rs:164`.** It says `into_parts` moves the values buffer without copying and that the work is `O(null_count)` rather than `O(n)`. Line 171 is `values.to_vec()`, which is a full `O(n)` copy, and `int_lengths.clone()` bumps the buffer refcount while `lengths` is still alive so there is no way to reclaim it as written. The `set_indices` loop itself is genuinely `O(null_count)`, but the function is not. Could you reword it? `optimizing_expressions.md` now points contributors here as the reference for this technique, so I would rather the comment not promise more than the code delivers.
--
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: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233#issuecomment-5192826908
Open an issue #5272 to track LargeList
--
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: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove merged PR #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233
--
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: compute spark_size list lengths with Arrow length kernel [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on PR #5233:
URL: https://github.com/apache/datafusion-comet/pull/5233#issuecomment-5193000732
Thanks @andygrove for review, PR updated
Modify the documentation and open an issue to track LargeList
--
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