Skip to content
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

Hash keys once #194

Merged
merged 2 commits into from
Apr 27, 2022
Merged

Hash keys once #194

merged 2 commits into from
Apr 27, 2022

Conversation

stepancheg
Copy link
Contributor

Two commits:

  • switch to hashbrown
  • use hashbrown raw_entry API to avoid hashing keys twice

Hashing twice issue can be solved by storing (K, hash) instead K in inner hashmap and supplying custom hash function.

With hashbrown raw entry API it is also possible to implement Equivalent API #183.

The downside of this diff is that shards function now exposes hashbrown maps instead of std maps (switching to (K, hash) has the same issue) .

The alternative to this diff is to wait for stabilization of rust-lang/rust#56167, as pointed in #183.

Used in the following commit to avoid hashing key twice.
Hashbrown `HashMap` provides API to work with prehashed keys.
@xacrimon xacrimon merged commit 3d315aa into xacrimon:master Apr 27, 2022
xacrimon added a commit that referenced this pull request May 2, 2022
@@ -43,7 +43,7 @@ cfg_if! {
}
}

pub(crate) type HashMap<K, V, S> = std::collections::HashMap<K, SharedValue<V>, S>;
Copy link

@Veykril Veykril Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type alias is exposed by public facing apis and therefor is a semver breakage, this was experienced in using one of the rust-analyzer crates as a dependency rust-lang/rust-analyzer#12344 (comment)

Copy link
Owner

@xacrimon xacrimon Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veykril Hey! This is indeed a semver breakage, however this is only visible if you use the raw_api feature which exposes the raw shards. I should probably do a better job at noting this in crate level documentation but this feature is unstable, this means you need to pin the versions if you rely on the types from that API as it may change due to internal needs like this PR and an internal lock change that was also done recently.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, good to know!

@arthurprs
Copy link
Contributor

AFACT this got reverted as part of another bug fix, but I guess can be re-added?

@arthurprs arthurprs mentioned this pull request Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants