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

Don't hash the key if dictionary is empty #44341

Merged
merged 1 commit into from
Feb 25, 2022
Merged

Don't hash the key if dictionary is empty #44341

merged 1 commit into from
Feb 25, 2022

Conversation

KristofferC
Copy link
Sponsor Member

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.

Copy link
Member

@Sacha0 Sacha0 left a comment

Choose a reason for hiding this comment

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

Heh nice 😄

@KristofferC KristofferC changed the title return immidiately from ht_keyindex if dictionary is empty Don't hash the key if dictionary is empty Feb 25, 2022
@oscardssmith
Copy link
Member

We can probably do one better, and check skip the hash for 1 element dictionaries as well (since there is only 1 place it can live)

@vtjnash vtjnash merged commit a2e4226 into master Feb 25, 2022
@vtjnash vtjnash deleted the kc/fast_dict branch February 25, 2022 18:06
@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 25, 2022

There is only 1 place, but where is that place?

Related thought: I think it would be great to make Dict for less than a few elements actually just be semi-dense linear lists (roughly equivalent to defining hash(k)===1 if sz(d)<threshold). Only once it reaches a threshold would it start to use the real hashes.

staticfloat pushed a commit to JuliaCI/julia-buildkite-testing that referenced this pull request Mar 2, 2022
…ng#44341)

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…ng#44341)

Avoids hashing the input key for empty dictionaries.

Inspired by rust-lang/hashbrown#305.
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.

None yet

4 participants