Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] Use a union to reduce the size of SmallVec #92
Conversation
Amanieu
force-pushed the
Amanieu:union
branch
from
f630ea1
to
02a19d7
Apr 17, 2018
Amanieu
force-pushed the
Amanieu:union
branch
from
02a19d7
to
8f0a47e
Apr 17, 2018
This comment has been minimized.
This comment has been minimized.
|
Hmm there seems to be a regression in the benchmark results. I will look into this.
|
| unsafe fn heap(&self) -> (*mut A::Item, usize) { | ||
| match *self { | ||
| SmallVecData::Heap(data) => data, | ||
| _ => unreachable!(), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
You might want to recommit this without rustfmt. Ideally, the rustfmt would be a seperate PR. Also, is the change from an |
mbrubeck
changed the title
Use a union to reduce the size of SmallVec
[WIP] Use a union to reduce the size of SmallVec
May 8, 2018
This comment has been minimized.
This comment has been minimized.
|
I'm going to close this since I haven't had time to work on it lately. |
Amanieu
closed this
May 9, 2018
arthurprs
referenced this pull request
May 10, 2018
Merged
Use a union to reduce the size of SmallVec [v2] #94
added a commit
that referenced
this pull request
Jun 6, 2018
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.
Amanieu commentedApr 17, 2018
•
edited by larsbergstrom
Uses a union to eliminate the space used by the
enumdeterminant. The new layout looks like this:The
capacityfield is used to determine which of the two union variants is active:capacity <= A::size()then the inline variant is used andcapacityholds the current length of the vector (number of elements actually in use).capacity > A::size()then the heap variant is used andcapacityholds the size of the memory allocation.Since unions with drop are still currently unstable, this is kept behind a "union" cargo feature, which falls back to an implementation using an enum if disabled.
This change is