warrenzhu25 commented on PR #27938: URL: https://github.com/apache/datafusion/pull/27938#issuecomment-7389618282
Thanks for checking! I instrumented `main` with `target_partitions = 1, 2, 4` and confirmed both effects: - **Multi-partition (`target_partitions = 4`, `Final` stage):** Matches what you saw — `ArrayAggGroupsAccumulator::evaluate` produced `dict_values = 50,062` with only `12,500` referenced (`25.0%`, `101.5 MB` in memory, `389 MB` spilled across 8 spills). Pruning unreferenced dictionary values in `ArrayAggGroupsAccumulator::evaluate` (via `garbage_collect_any_dictionary`) fixes this in-memory bloat. - **Single-partition (`target_partitions = 1`, `Single` stage):** `referenced` is `100%` (`22,965 / 22,965`, `24.1 MB`), so there are no unreferenced entries to prune in the accumulator. The reason each spill file only had 1 chunk (`32/32` rows) on `main` is that `SpilledRowSizes` saw `keys >= 2 * values`, returned `compacted_cols = []`, and only counted the 4-byte keys — so `sorts::stream` thought all 32 groups fit under `max_batch_bytes = 1 MB` and wrote one 24 MB chunk per spill file. On replay, reading 3 spill files simultaneously then hit `ResourcesExhausted` (`45.9 MB > 24 MB`). With `SpilledRowSizes` compacting `List<Dictionary>` when values aren't shared across groups, each spill file is split into ~1 MB chunks with compacted dictionaries, and replay fits comfortably in 24 MB. So we actually benefit from **both**: 1. Keeping the `SpilledRowSizes` fix for `List<Dictionary>` so spill chunking/compaction works even when 100% of dictionary values are referenced (and `target_partitions = 1` doesn't OOM on replay), and 2. Pruning unreferenced dictionary values in `ArrayAggGroupsAccumulator::evaluate` so multi-partition `Final` state batches don't stay 2x–4x bloated in memory. Would you like me to include the `ArrayAggGroupsAccumulator` dictionary pruning in this PR as well, or keep it as a separate follow-up PR? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
