Expand description
A thin and small vector
that can fit data into a single usize
.
See the readme on GitHub for detailed explanation of the memory layout.
§When to use
Although the technical limit is N <= 127
,
it is not meaningful to set N
such that align_of::<T>() + N * size_of::<T>()
exceeds 24;
WordVec
has no advantage over SmallVec
if it cannot pack into a smaller struct.
Thin vectors are significantly (several times) slower than conventional vectors
since reading the length and capacity usually involves accessing memory out of active cache.
Thus, heap layout is supposed to be the cold path.
In other words, WordVec
is basically
“length should never exceed N
, but behavior is still correct when it exceeds”.
Since the length encoding in the inlined layout is indirect (involves a bitshift),
raw inlined access also tends to be slower in WordVec
compared to SmallVec
,
as a tradeoff of reduced memory footprint of each vector alone.
This may get handy in scenarios with a large array of small vectors,
e.g. as an ECS component.
Structs§
- Into
Iter - Implements
IntoIterator
forWordVec
. - WordVec
- A thin and small vector that can fit data into a single
usize
.