-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
HashMap: Does not reserve in extend #36579
Comments
This should probably be closed ("WONTFIX") if we accept that hashmaps must be ready for being extended with iterators that are just duplicates of existing keys (i.e. no growth needed). |
Hmm, yeah, the overlap case is interesting. Probably worth discussing with @rust-lang/libs but I think I agree that the current no reserve behavior is the way to go. |
Closing due to this comment but the libs team is very interested in exploring our options here! |
I think the decision here is a bit too conservative, we should discuss some sort of middle ground (even if arbitrary). The stdlib HM is optimized for reads, not writes, and this decision sort of goes against that. From the top of my head I can think of two ways to move this forward
|
Smarter HashMap/HashSet pre-allocation for extend/from_iter HashMap/HashSet from_iter and extend are making totally different assumptions. A more balanced decision may allocate half the lower hint (rounding up). For "well defined" iterators this effectively limits the worst case to two resizes (the initial reserve + one resize). cc #36579 cc @bluss
HashMap: Does not reserve in extend. This exacerbates the performance pathology when extending one map with another, mentioned in #36481.
(I'm working on a fix)The text was updated successfully, but these errors were encountered: