fluss
fluss copied to clipboard
[kv] Optimize distinct array aggregations
Search before asking
- [x] I searched existing issues and found no separate performance request. #5172 and #5174 introduce optional distinct handling for last_n.
Motivation
Distinct array aggregations can spend substantial CPU and allocation on element materialization, collection nodes, hashing and result encoding. collect(distinct) and last_n(distinct) should be evaluated together so performance improvements do not create separate, expanding implementations for each function.
Solution
- Establish reproducible aggregation-plus-encoding benchmarks for both functions, including scalar and nested values, bytes, repeated values, mixed input representations and different collection sizes.
- Evaluate allocation reduction, binary-array copying, primitive hashing and bounded temporary memory using paired measurements against the standard-collection implementations.
- Keep each function's ordering and retention rules explicit: collect retains first occurrences; last_n retains the last N distinct values by last occurrence.
- Share value-equality or indexing logic only where the functions need the same contract. Existing cross-encoding differences in collect's nested-value equality are correctness concerns and must be distinguished from performance changes.
- Include the cost of memory retention, large inputs and MAP entry ordering; report tradeoffs rather than only favorable cases.
Anything else?
Keep the functional last_n change in #5174 independently reviewable. A draft optimization PR can start with last_n and provide evidence for subsequent collect improvements; this issue remains open until both functions have been evaluated.
Willingness to contribute
- [x] I'm willing to submit a PR!