perf: optimizing take_n for DictionaryGroupValuesColumn - #24476
perf: optimizing take_n for DictionaryGroupValuesColumn#24476saadtajwar wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24476 +/- ##
==========================================
- Coverage 81.31% 81.30% -0.01%
==========================================
Files 1117 1117
Lines 395911 395981 +70
Branches 395911 395981 +70
==========================================
+ Hits 321918 321948 +30
- Misses 55177 55209 +32
- Partials 18816 18824 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@Rich-T-kid & @kumarUjjawal - ready for review! Thanks in advance for your feedback! |
|
run benchmark dictionary_group_values |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing saadtajwar/DictionaryGroupValuesColumn-take-n-optimization (901e301) to dbdc627 (merge-base) diff Run configurationrun benchmark dictionary_group_valuesResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing saadtajwar/DictionaryGroupValuesColumn-take-n-optimization (901e301) to dbdc627 (merge-base) diff Run configurationrun benchmark dictionary_group_valuesCPU Details (lscpu)Details
Resource Usagedictionary_group_values — base (merge-base)
dictionary_group_values — branch
File an issue against this benchmark runner |
|
Oof, if I'm reading this correctly this doesn't look like a huge win for us here...any thoughts on how we want move forward here? I feel like we could either:
My preference would be the last option, but I'm obviously biased in wanting to see these changes move the needle 😆 open to any feedback! |
Which issue does this PR close?
Rationale for this change (copied from issue)
DictionaryGroupValuesColumn::take_n emits the first n groups and rebuilds the remainder in-place. Every call hashes all surviving distinct values from scratch to reconstruct value_dedup, making repeated partial emissions O(G² / batch_size) over the lifetime of a query, where G is the total number of distinct values seen. Additionally, arrow::compute::take does not compact the backing storage for Utf8View, BinaryView, or nested dictionary value arrays; the rebuilt column retains a reference to the full original allocation rather than releasing memory proportional to the dropped groups. Under a high-cardinality dictionary key with frequent spill-driven partial emissions (e.g. streaming aggregation with a large fan-out), this combination causes both CPU and peak RSS to grow super-linearly with group count.
What changes are included in this PR?
value_dedupto only remove/move relevant slots instead of complete rebuildinnerfor the remainder loopAre these changes tested?
Yes
Are there any user-facing changes?
No