-
Notifications
You must be signed in to change notification settings - Fork 289
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
Dropping empty map takes time proportional to capacity #170
Comments
jonhoo
added a commit
to jonhoo/hashbrown
that referenced
this issue
Jul 1, 2020
Partial fix for rust-lang#170.
I suppose this is mitigated by the fact that we iterate over the control bytes, not the actual buckets, so we're iterating through many buckets at once. Even so, it seems like it'd be nice to avoid this iteration altogether when we can? |
I guess the places that check |
Yup: jonhoo@8dd0412 |
bors
added a commit
that referenced
this issue
Aug 4, 2020
Do not iterate to drop if empty If the table is empty, there is no need to iterate over all the buckets in order to drop their contents. Fixes #170.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We currently iterate over the map on drop:
hashbrown/src/raw/mod.rs
Lines 1194 to 1195 in efbd036
And the iterator iterates over all the buckets, even if it knows there are no more items (
RawIter::items == 0
):hashbrown/src/raw/mod.rs
Lines 1401 to 1402 in efbd036
This means that code like this will unnecessarily take fairly long:
The above is a little contrived, but the same occurs if the caller calls
drain
orclear
, and then drops the map. Not sure if this is something we want to optimize for, but the fix is fairly straightforward.The text was updated successfully, but these errors were encountered: