-
Notifications
You must be signed in to change notification settings - Fork 154
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
Unify the entry and insert code #126
Conversation
(index, None) | ||
} | ||
fn steal(self, entry: VacantEntry<'a, K, V>) -> Self::Output { | ||
let index = entry.map.entries.len(); |
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.
this could be just entry.insert_impl::<Sz>(self.0)
right? Something like that to reduce duplication - even hit could use that(?)
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.
Ah good idea. Do you mean empty
could use that? I was afraid that entering the probe loop another time would be costly (technically, you don't have to in the empty case), but it seems to be fine.
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.
Nvm, turns out doing it in empty
isn't great, it basically removes the fast path that the old insert code had, making steal and empty the same.
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.
Are we then maybe identifying the main thing that slows down entry compared with the old insert? Maybe if we updated entry's VacantEntry to skip that loop, for the non-steal case, that insert and entry would match each other in performance?
That's awesome |
Could you update the PR description to use one of the formulations that means that #108 is closed when this is merged? :) https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword |
Done! |
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.
LGTM -- just one typo noted...
Thanks. I'll merge this when I have time to make some post-merge edits |
@bluss can I help with whatever is blocking this? |
I'll add it as comments. I thought I might as well merge and edit myself, sometimes I prefer that to the back-and-forth, just don't want reviews to be too perfectionist |
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 a lot for making this PR and improving indexmap. I just put comments on the small things I'd edit if I had time
key: entry.key, | ||
value: self.0, | ||
}); | ||
(index, None) |
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.
This method body seems "loose" like this - could it not just call a method on the entry? I general, it's hard to follow the insert logic when it's spread out.
(This comment is rather perfectionist, and not something I wanted to make a requirement to fix before merging).
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.
I looked at this -- you'd basically want VacantEntry::insert_impl
without the probe loop (since we know its empty). But this needs to consume the entry's key, which makes it harder to reuse that code, so I think we'd end up writing this code separately either way. i.e. It doesn't really matter whether we do it here or there.
(And frankly, a lot of this will disappear if I land the hashbrown changes...)
Yeah, I get that, and sometimes I'll take advantage of maintainer pushes to PRs for that same reason. I'm pressing because I'm building up changes toward using indexmap more in rustc. 🙂 |
I fixed the spacing nit, and I think we can wait on the other point. Thanks @mwillsey! |
This will close #108
This doesn't so much improve the entry code rather than abstract away
entry
andinsert
into aProbeAction
. This forces monomorphization to give us the insert fast path that doesn't require the additional indirection that entry does.It also implements
insert_full
on that fast path (insert
is now just a call toinsert_full
), so that should be much faster as well, since it was formerly implemented in terms ofentry
.Benchmarks