perf: compute cardinality from list/map offsets - #25079
Open
neilconway wants to merge 1 commit into
Open
Conversation
`cardinality` was implemented by iterating over the `values` of the input `GenericListArray`, creating a slice for each logical row, and then fetching the length of the slice. This incurs a lot of unnecessary per-row overhead; we can instead determine the cardinality of each list by looking at the `OffsetBuffer`. For non-nested lists, this is straightforward. It would be possible to use a similar approach to compute the cardinality of nested lists, but for now this PR falls back to the previous approach for that case. Add a benchmark, plus tests for lists (sliced, unsliced, LargeList) and maps, including nulls and empty batches. Benchmarks: (M4 Max) list/valid/8192x32, 203.951 µs → 0.984 µs, -99.52% large_list/nullable/8192x32, 172.699 µs → 1.049 µs, -99.39% map/valid/8192x32, 471.074 µs → 0.958 µs, -99.80%
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25079 +/- ##
==========================================
- Coverage 81.74% 81.74% -0.01%
==========================================
Files 1128 1128
Lines 416644 416698 +54
Branches 416644 416698 +54
==========================================
+ Hits 340592 340635 +43
- Misses 55995 56000 +5
- Partials 20057 20063 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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?
cardinalityfrom offsets #25078Rationale for this change
cardinalitywas implemented by iterating over thevaluesof the inputGenericListArray, creating a slice for each logical row, and then fetching the length of the slice. This incurs a lot of unnecessary per-row overhead; we can instead determine the cardinality of each list by looking at theOffsetBuffer. This is roughly 100x-500x faster.For non-nested lists, this is straightforward. It would be possible to use a similar approach to compute the cardinality of nested lists, but for now this PR falls back to the previous approach for that case.
Benchmarks: (M4 Max)
list/valid/8192x32, 203.951 µs → 0.984 µs, -99.52%
large_list/nullable/8192x32, 172.699 µs → 1.049 µs, -99.39%
map/valid/8192x32, 471.074 µs → 0.958 µs, -99.80%
What changes are included in this PR?
cardinalityfor non-nested lists/mapsWhat is the testing strategy for this PR?
Existing tests pass; new tests added.
Are there any user-facing changes?
No.