Prefer boxed slices over vectors internally#863
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #863 +/- ##
==========================================
+ Coverage 93.48% 93.77% +0.28%
==========================================
Files 48 48
Lines 6771 6696 -75
==========================================
- Hits 6330 6279 -51
+ Misses 441 417 -24 ☔ View full report in Codecov by Sentry. |
|
@phimuemue I noted that collect to
The only place I've thought of |
scottmcm
left a comment
There was a problem hiding this comment.
Since they're stored in state enums this is worth considering, and since it looks like they're created from ExactSizeIterator sources anyway so it's probably not going to mean an extra re-allocation (as the collect will use that size hint), this makes good sense to me.
I was thinking about the cases where we keep the |
|
@phimuemue I think it has sense when we know it won't ever grow and we don't repeatedly shrink it. There is not that many cases in itertools: |
While reading This Week in Rust 531 and specifically Identifying Rust's
collect::<Vec<_>>()memory leak footgun, I got the remainder thatSo I went through our codebase and found three places to apply this: two are committed and
MultiProduct. I thought I would wait #835 to be merged to do it there too but I reached one limitation of edition 2018 (inlastspecialization) so I'm not.The other vectors we internally use do not have a fixed length. Such as
Combinationsthat has a growing vector in order forPowersetto work too.(And I obviously do not want to break our iterators generating vectors when it could be boxed slices.)