-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer boxed slices over vectors internally #863
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good catch. I think we should do this and trust that the additional into_boxed_slice
does not need to reallocate, and, thus, can be optimized to a no-op.
As for the space consumption problem: Should we shrink_to_fit
to avoid this?
@phimuemue I noted that collect to
The only place I've thought of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
a0411d6
@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 (inlast
specialization) so I'm not.The other vectors we internally use do not have a fixed length. Such as
Combinations
that has a growing vector in order forPowerset
to work too.(And I obviously do not want to break our iterators generating vectors when it could be boxed slices.)