-
Notifications
You must be signed in to change notification settings - Fork 215
Closed
Labels
A-performanceArea: Performance (CPU, Memory)Area: Performance (CPU, Memory)C-localeComponent: Locale identifiers, BCP47Component: Locale identifiers, BCP47S-epicSize: Major project (create smaller child issues)Size: Major project (create smaller child issues)T-enhancementType: Nice-to-have but not requiredType: Nice-to-have but not requiredblockedA dependency must be resolved before this is actionableA dependency must be resolved before this is actionablehelp wantedIssue needs an assigneeIssue needs an assignee
Milestone
Description
Currently, we define ShortVec
to be
enum ShortVec<T> {
Empty,
Single(T),
Multi(Vec<T>),
}
This 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:
enum ShortBoxSlice<T> {
ZeroOne(Option<T>),
Multi(Box<[T]>),
}
(thanks @Manishearth and @mikebenfield)
Some notes:
- This depends on the Rust upstream PR Use niche-filling optimization even when multiple variants have data. rust-lang/rust#94075 landing first
- For this to work for
Variant
, which is the motivating use case, we need to fix Make Option<TinyAsciiStr> be the same size as TinyAsciiStr #2083 first - It hopefully won't be necessary to expand the
Box
into an explicitNonZeroPtr
pointer andNonZeroUsize
length, but that is an option we could pursue if needed
Metadata
Metadata
Assignees
Labels
A-performanceArea: Performance (CPU, Memory)Area: Performance (CPU, Memory)C-localeComponent: Locale identifiers, BCP47Component: Locale identifiers, BCP47S-epicSize: Major project (create smaller child issues)Size: Major project (create smaller child issues)T-enhancementType: Nice-to-have but not requiredType: Nice-to-have but not requiredblockedA dependency must be resolved before this is actionableA dependency must be resolved before this is actionablehelp wantedIssue needs an assigneeIssue needs an assignee