A Rust vector that keeps a few items on the stack before it allocates
open sourceMIT OR Apache-2.0free
SmallVec is an open source Rust library implementing the 'small vector' optimization: a vector type that stores up to a fixed number of items inline on the stack and only moves to the heap when it grows past that. It comes from the Servo project and is used inside the Rust compiler, which uses it in many places to improve performance.
Problems it solves
- avoid a heap allocation for short vectors in hot Rust code
- a Rust Vec that keeps its first few elements on the stack
- reduce allocations in a performance-sensitive Rust program that builds many small lists
Features
- stores a small number of items inline on the stack
- spills to the heap only when it grows past its inline capacity
- used inside the Rust compiler
Limitations
- Version 2 is a pre-release on the main branch; the released 1.x line is maintained on the v1 branch1
Alternatives
The same job
These do what SmallVec does.
- arrayvec Rust vector and string types with fixed capacity, stored inline