-
Notifications
You must be signed in to change notification settings - Fork 183
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
Reduce stack size of ShortVec in icu_locid, helping reduce Locale & LanguageIdentifier #2084
Comments
If we want to go further than the Once on the heap we can make |
Edited, had a typo that messed up results before. I didn't sleep much. I just tried this with today's nightly: enum ShortVec<T> {
Empty,
Single(T),
Multi(Vec<T>),
}
assert_eq!(size_of::<ShortVec<usize>>(), 32);
assert_eq!(size_of::<ShortVec<NonZeroUsize>>(), 32);
enum ShortVec2<T> {
Empty,
Single(T),
Multi(Box<[T]>),
}
assert_eq!(size_of::<ShortVec2<usize>>(), 24);
assert_eq!(size_of::<ShortVec2<NonZeroUsize>>(), 24);
enum ShortVec3<T> {
ZeroOne(Option<T>),
Multi(Box<[T]>),
}
assert_eq!(size_of::<ShortVec3<usize>>(), 24);
assert_eq!(size_of::<ShortVec3<NonZeroUsize>>(), 16); // this is 24 on 1.64 |
Don't celebrate, this seems very brittle and won't work with |
This comment was marked as resolved.
This comment was marked as resolved.
Oh, wait, it's fine. It should be an array of |
Oh yeah. But will it work with a struct around the array? 🤷♂️ |
FWIW, if it's strongly preferable for you all to maintain the 3 variants like
and for That would actually be achievable with the changes from this PR plus one more easy optimization that maybe I should add to it anyway. However, no guarantees about when that PR gets merged; I'm kind of waiting on something else before I continue work on it. |
Yes that would be ideal. I filed rust-lang/rust#102997 about this. |
Let's go with |
@pdogr implemented If we use |
Closed by #3220 |
Currently, we define
ShortVec
to beThis requires 32 bytes on x86_64:
Vec<T>
is 3*usize (24 bytes), and the discriminant requires one additional word.Pending some dependencies, for
T = NonZeroUsize
and smaller, 16 bytes should be achievable as follows:(thanks @Manishearth and @mikebenfield)
Some notes:
Variant
, which is the motivating use case, we need to fix Make Option<TinyAsciiStr> be the same size as TinyAsciiStr #2083 firstBox
into an explicitNonZeroPtr
pointer andNonZeroUsize
length, but that is an option we could pursue if neededThe text was updated successfully, but these errors were encountered: