Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upCollecting into a Result<Vec<_>> doesn't reserve the capacity in advance #48994
Comments
This comment has been minimized.
This comment has been minimized.
|
I wonder if there's a more general tweak. It looks like collect only looks at the low end of the hint (https://doc.rust-lang.org/src/alloc/vec.rs.html#1804), so it feels like there ought to be a way to get some use out of the high end as well. Strawman proposal:
Probably needs the benchmark set to decide whether it's constructive, though... |
added a commit
to scurest/apicula
that referenced
this issue
Mar 15, 2018
Centril
added
I-slow
T-libs
labels
Mar 16, 2018
Aaronepower
added
the
C-enhancement
label
May 21, 2018
ljedrz
referenced a pull request that will
close
this issue
Jul 31, 2018
Open
[WIP] Calculate capacity when collecting into Option and Result #52910
added a commit
to cramertj/rust
that referenced
this issue
Aug 2, 2018
scottmcm
referenced this issue
Aug 5, 2018
Closed
Try to guess a smarter initial capacity in Vec::from_iter #53086
added a commit
that referenced
this issue
Aug 5, 2018
added a commit
that referenced
this issue
Aug 8, 2018
ljedrz
referenced this issue
Nov 5, 2018
Closed
Preallocate the vector containing predicates in decode_predicates #55534
added a commit
that referenced
this issue
Feb 1, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scurest commentedMar 13, 2018
•
edited
Couldn't find an issue for this and don't know if it counts but filing anyway.
If you have
the
SpecExtendmachinery ensures that the vector hass.len()space reserved in advance. However if you change it to return a resultthen (based on examining the LLVM IR and heaptracker's "Temporary" measurements) that optimization has quietly been lost.
This is technically correct in the sense that the first element yielded could be an
Errof course (the size hint for theAdapterinResult'sFromIteratorimpl has a lower bound of 0). But this pessimizes the good path to take more memory and be slower in favor of possibly saving memory on the bad one, which seems backwards.Is there a specialization that could be added to fix this?