Repository navigation
Use process_results to avoid intermediate Vec allocations - #8448
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis pull request refactors two functions in the collection library to use itertools utilities more efficiently. The first change in Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip Migrating from UI to YAML configuration.Use the |
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]>
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]>
Summary
scroll_by_field, the iterator of segment read results was collected into aVeconly to be immediately iterated again withkmerge_by. Useitertools::process_resultsto pipe the unwrapped results directly into the merge chain, avoiding the heap allocation.GroupsAggregator::add_point, group keys were collected into aVec<GroupId>only to be immediately iterated with.unique(). Useprocess_resultsto combine both steps and eliminate the intermediate allocation.Test plan
cargo check -p collectionpassescargo +nightly fmt --all -- --checkpassesMade with Cursor