You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is an issue I found when testing the performance of vector type, but apparently this applies to all collections.
The code uses itertools to collect fallible items into a Vec<Result<...>>:
Unfortunately itertools does not use the size hint in this case and does not reserve proper space in the returned vector.
Instead, it grows the vector as more items are added.
Also it the size hint for ListLikeIterator doesn't look correct anyways (it delegates to raw iterator, which provides the default None hint).
This can be trivially fixed by creating the vector with proper capacity first (we know the number of elements very early on and it is stored in the field of ListLikeIterator) and then adding the items with e.g. extend.
The text was updated successfully, but these errors were encountered:
This is an issue I found when testing the performance of vector type, but apparently this applies to all collections.
The code uses itertools to collect fallible items into a
Vec<Result<...>>
:Unfortunately itertools does not use the size hint in this case and does not reserve proper space in the returned vector.
Instead, it grows the vector as more items are added.
Also it the size hint for
ListLikeIterator
doesn't look correct anyways (it delegates to raw iterator, which provides the default None hint).This can be trivially fixed by creating the vector with proper capacity first (we know the number of elements very early on and it is stored in the field of
ListLikeIterator
) and then adding the items with e.g.extend
.The text was updated successfully, but these errors were encountered: