-
Notifications
You must be signed in to change notification settings - Fork 292
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
Another attempt to reduce size_of<HashMap> #159
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- `data` field is removed, instead the allocation layout is changed such that first element of control bytes start exactly at one past last element of data table. So we just use negative index to access data table without touching size field. - Rewritten `calculate_layout` to remove padding between two tables, its placed either at start or end of allocation if necessary.
fix build failure
doing `ptr as usize as *mut _` does escape from miri analysis ``` ptr: NonNull::new_unchecked(ptr), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a potentially NULL pointer, but expected something that cannot possibly fail to be greater or equal to 1 ``` I am not sure if this is correct way to fix it.
Amanieu
reviewed
May 19, 2020
- Removed unnecessary padding at the end of `calculate_layout` - Put back old comments - Renamed some functions - Use `#[cfg(feature = "...")]` instead `#[allow(dead_code)]`
- nightly version of calculate_layout was putting padding between two tables in some cases, fixed. Also added debug_assert! to check this. - use wrapping_sub() instead sub() in data_start() (empty RawTable returns buckets() == 1, crosses allocation bounds)
Amanieu
reviewed
May 22, 2020
- Removed unnecessary code from nightly `calculate_layout` - Added comment for `Bucket::ptr` data member
removed wrong assertation code
@bors r+ |
📌 Commit b500a0a has been approved by |
☀️ Test successful - checks-travis |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 7, 2020
Update hashbrown to 0.8.1 This update includes: - rust-lang/hashbrown#146, which improves the performance of `Clone` and implements `clone_from`. - rust-lang/hashbrown#159, which reduces the size of `HashMap` by 8 bytes. - rust-lang/hashbrown#162, which avoids creating small 1-element tables. Fixes rust-lang#28481
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Aug 29, 2020
Upgrade to rustc 1.48.0-nightly (d006f5734 2020-08-28) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Nov 11, 2020
Upgrade to rustc 1.48.0-nightly (d006f5734 2020-08-28) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Nov 12, 2020
Upgrade to rustc 1.48.0-nightly (d006f5734 2020-08-28) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 25, 2021
Upgrade to rustc 1.51.0-nightly (1d0d76f8d 2021-01-24) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 25, 2021
Upgrade to rustc 1.51.0-nightly (1d0d76f8d 2021-01-24) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 25, 2021
Upgrade to rustc 1.51.0-nightly (1d0d76f8d 2021-01-24) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 26, 2021
Upgrade to rustc 1.49.0-nightly (5404efc28 2020-11-11) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 26, 2021
Upgrade to rustc 1.48.0-nightly (623fb90b5 2020-09-26) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Jan 26, 2021
Upgrade to rustc 1.48.0-nightly (623fb90b5 2020-09-26) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Feb 25, 2021
Upgrade to rustc 1.48.0-nightly (623fb90b5 2020-09-26) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Feb 25, 2021
Upgrade to rustc 1.48.0-nightly (623fb90b5 2020-09-26) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
bors-servo
added a commit
to servo/servo
that referenced
this pull request
Feb 25, 2021
Upgrade to rustc 1.48.0-nightly (623fb90b5 2020-09-26) rust-lang/hashbrown#159 reduced `size_of::<HashMap>()`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#69
Changes made
data
field is removed, instead the allocation layout is changed such that first element of control bytes start exactly at one past last element of bucket table. So we just use negative index to access bucket table without touching size field. Allocation layout looks like this:hashbrown/src/raw/mod.rs
Lines 359 to 361 in 7027781
calculate_layout
implementation:[Paddings] | [Buckets] | [Ctrls]
, previously it was[Ctrls] | [Paddings] | [Buckets]
Bucket::add
toBucket::next_n
Drawbacks
Issues
Bucket::as_ptr()
on one past last element yields UB (crosses allocation boundary).data_start()
doesn't equaldata_end()
when table is empty because empty table returns buckets() == 1cargo benchcmp (from local)
Some of results vary a lot in my tests, they seem roughly same except
clone_from_large
is slower.