pub type StaticVec<T> = SmallVec<[T; 3]>;
Expand description
(internals) Alias to smallvec::SmallVec<[T; 3]>
,
which is a Vec
backed by a small, inline, fixed-size array when there are ≤ 3 items stored.
Exported under the internals
feature only.
§History
And Saint Attila raised the SmallVec
up on high, saying, “O Lord, bless this Thy SmallVec
that, with it, Thou mayest blow Thine allocation costs to tiny bits in Thy mercy.”
And the Lord did grin, and the people did feast upon the lambs and sloths and carp and anchovies and orangutans and breakfast cereals and fruit bats and large chu…
And the Lord spake, saying, “First shalt thou depend on the smallvec
crate.
Then, shalt thou keep three inline. No more. No less. Three shalt be the number thou shalt keep inline,
and the number to keep inline shalt be three. Four shalt thou not keep inline, nor either keep inline
thou two, excepting that thou then proceed to three. Five is right out. Once the number three,
being the third number, be reached, then, lobbest thou thy SmallVec
towards thy heap, who,
being slow and cache-naughty in My sight, shall snuff it.”
§Why Three
StaticVec
is used frequently to keep small lists of items in inline (non-heap) storage in
order to improve cache friendliness and reduce indirections.
The number 3, other than being the holy number, is carefully chosen for a balance between storage space and reduce allocations. That is because most function calls (and most functions, for that matter) contain fewer than 4 arguments, the exception being closures that capture a large number of external variables.
In addition, most script blocks either contain many statements, or just one or two lines;
most scripts load fewer than 4 external modules; most module paths contain fewer than 4 levels
(e.g. std::collections::map::HashMap
is 4 levels and it is just about as long as they get).
Aliased Type§
struct StaticVec<T> { /* private fields */ }