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

Alternate layout with more space for small inline elements? #276

Open
typesanitizer opened this issue Jan 30, 2022 · 2 comments
Open

Alternate layout with more space for small inline elements? #276

typesanitizer opened this issue Jan 30, 2022 · 2 comments

Comments

@typesanitizer
Copy link

typesanitizer commented Jan 30, 2022

On a 64-bit platform, the current implementation (with the union feature flag) only allows for 16 u8s / 4 u32s inline if the total size of a SmallVec is 24 bytes. This is because the capacity unconditionally takes up 8 bytes as it is a usize. Would it make sense to only use 56 bits from the capacity (larger capacities are impractical anyways), and use the LSB/MSB (depending on endianness) of the capacity as a boolean?

That way, one could fit in 23 u8 values or 5 u32 values in the same space.

Happy to submit a patch if this would be useful.

@appetrosyan
Copy link

We use smallvec as a space saving feature. Being able to cram more values inline would be invaluable.

@typesanitizer
Copy link
Author

I took a shot at implementing this, but I don't know enough about the invariants required around the use of MaybeUninit and the what is safe to assume around offsets and alignment to make this work properly. I've implemented similar functionality in one of my crates but that is a more specialized situation with u8 array (so zeroing the array is fine).

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

No branches or pull requests

2 participants