Skip to content

Use process_results to avoid intermediate Vec allocations - #8448

Merged
agourlay merged 1 commit into
devfrom
use-process-results-avoid-collect-alloc
Mar 18, 2026
Merged

agourlay merged 1 commit into
devfrom
use-process-results-avoid-collect-alloc

Conversation

@qdrant-cloud-bot

Copy link
Copy Markdown
Contributor

Summary

  • In scroll_by_field, the iterator of segment read results was collected into a Vec only to be immediately iterated again with kmerge_by. Use itertools::process_results to pipe the unwrapped results directly into the merge chain, avoiding the heap allocation.
  • In GroupsAggregator::add_point, group keys were collected into a Vec<GroupId> only to be immediately iterated with .unique(). Use process_results to combine both steps and eliminate the intermediate allocation.

Test plan

  • cargo check -p collection passes
  • cargo +nightly fmt --all -- --check passes
  • CI should confirm no regressions

Made with Cursor

In two places we collected an iterator of Results into a
Result<Vec<_>> only to immediately iterate the Vec again.
Use `itertools::process_results` instead to pipe the unwrapped
items straight into the downstream iterator chain, removing
the unnecessary heap allocation.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 51c3a99f-e451-4768-951b-a88fa3b19e6f

📥 Commits

Reviewing files that changed from the base of the PR and between f6acad5 and 840a786.

📒 Files selected for processing (2)
  • lib/collection/src/grouping/aggregator.rs
  • lib/collection/src/shards/local_shard/scroll.rs

📝 Walkthrough

Walkthrough

This pull request refactors two functions in the collection library to use itertools utilities more efficiently. The first change in aggregator.rs combines a two-step group key building process into a single streaming operation with deduplication, where payload values are converted to GroupIds and duplicates are filtered. The second change in scroll.rs wraps an iterator of reads with itertools::process_results to handle error propagation during result aggregation, kmerge, dedup, and limit operations. Both modifications preserve existing error handling semantics while simplifying the control flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: eliminating intermediate Vec allocations by using itertools::process_results.
Description check ✅ Passed The description is directly related to the changeset, providing specific details about both modified files and the optimization strategy employed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch use-process-results-avoid-collect-alloc
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@agourlay
agourlay requested a review from xzfc March 18, 2026 11:42
@agourlay
agourlay merged commit ea95e29 into dev Mar 18, 2026
15 checks passed
@agourlay
agourlay deleted the use-process-results-avoid-collect-alloc branch March 18, 2026 15:00
generall pushed a commit that referenced this pull request Mar 26, 2026
In two places we collected an iterator of Results into a
Result<Vec<_>> only to immediately iterate the Vec again.
Use `itertools::process_results` instead to pipe the unwrapped
items straight into the downstream iterator chain, removing
the unnecessary heap allocation.

Made-with: Cursor

Co-authored-by: Cursor Agent <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
In two places we collected an iterator of Results into a
Result<Vec<_>> only to immediately iterate the Vec again.
Use `itertools::process_results` instead to pipe the unwrapped
items straight into the downstream iterator chain, removing
the unnecessary heap allocation.

Made-with: Cursor

Co-authored-by: Cursor Agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants