Skip to content

Reduce stack size of ShortVec in icu_locid, helping reduce Locale & LanguageIdentifier #2084

@sffc

Description

@sffc

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:

  1. This depends on the Rust upstream PR Use niche-filling optimization even when multiple variants have data. rust-lang/rust#94075 landing first
  2. 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
  3. It hopefully won't be necessary to expand the Box into an explicit NonZeroPtr pointer and NonZeroUsize length, but that is an option we could pursue if needed

Metadata

Metadata

Assignees

Labels

A-performanceArea: Performance (CPU, Memory)C-localeComponent: Locale identifiers, BCP47S-epicSize: Major project (create smaller child issues)T-enhancementType: Nice-to-have but not requiredblockedA dependency must be resolved before this is actionablehelp wantedIssue needs an assignee

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions