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

std::hashmap: Tighter representation for the Bucket #9212

Closed
wants to merge 1 commit into from
Closed

std::hashmap: Tighter representation for the Bucket #9212

wants to merge 1 commit into from

Conversation

bluss
Copy link
Member

@bluss bluss commented Sep 15, 2013

Replace Option<Bucket<K, V>> with a custom
enum Bucket { Unused, Filled(hash, key, value) }. The non-nullable
pointer optimization for enums with two variants will be active with the
new representation, while it was not with the old. This is if either
K or V is a non-nullable pointer type.

With these changes, now Bucket<int,int> is 32 bytes (like before) but
Bucket<~str,int> is 24 bytes on 64-bit, so we save the 8 bytes of enum
tag per bucket.

Replace `Option<Bucket<K, V>>` with a custom
`enum Bucket { Unused, Filled(hash, key, value) }`. The non-nullable
pointer optimization for enums with two variants will be active with the
new representation, while it was not with the old. This is if either
K or V is a non-nullable pointer type.

With these changes, now `Bucket<int,int>` is 32 bytes and
`Bucket<~str,int>` is 24 bytes on 64-bit, so we save the 8 bytes of enum
tag per bucket.
@thestinger
Copy link
Contributor

I think we should just make the the adt.rs code smart enough to do this itself.

@thestinger
Copy link
Contributor

cc @jld

@jld
Copy link
Contributor

jld commented Sep 16, 2013

We probably should improve the optimization. (And that should get its own issue if it doesn't have one yet.) The monomorphizer would need to know enough about whatever adt.rs is extracting from the type to avoid merging Option<(int, ~int)> and Option<(~int, int)>, or Option<(int[2], ~int)> and Option<(int[3], ~int)>, or whatever.

@thestinger
Copy link
Contributor

@jld: I'm planning on replacing our type_use stuff with LLVM's mergefunc pass by the way, so stuff like this should get easier. #9216 is one of the current blockers.

@bluss
Copy link
Member Author

bluss commented Sep 21, 2013

Closing this Pull unmerged, in favor of the linked issue I opened.

@bluss bluss closed this Sep 21, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 31, 2023
New lint [`four_forward_slashes`]

Closes rust-lang#9212

changelog: New lint [`four_forward_slashes`]
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.

3 participants