smallvec
'Small vector' optimization: store up to a small number of items on the stack
This package has a good security score with no known vulnerabilities.
Community Reviews
Solid stack-allocated vector with minimal security surface
The main security consideration is around capacity handling. Unlike Vec, overflowing the inline capacity triggers heap allocation, which can have performance implications if you're counting on stack-only behavior for timing consistency. The library doesn't expose sensitive information through errors because panics are straightforward (out-of-bounds, allocation failures). No crypto, no network, no parsing complexity—just memory management.
One practical gotcha: the inline size is part of the type signature, so changing it breaks API compatibility. I've also seen teams accidentally use overly large inline sizes, bloating stack frames. The lack of built-in bounds checking on `from_buf_and_len` in unsafe contexts requires careful auditing during code review.
Best for: Performance-critical code paths where you need Vec-like semantics but want to avoid heap allocation for small collections.
Avoid if: You need dynamic resizing without type changes or cannot tolerate any unsafe code in your dependency tree.
Drop-in Vec replacement with excellent ergonomics and zero friction
Documentation is thorough with practical examples showing the performance trade-offs. The inline capacity optimization is transparent until you need to understand it, which is perfect API design. IDE autocomplete works flawlessly since it implements all the standard traits you'd expect (IntoIterator, Extend, Deref to slice, etc.).
One gotcha: choosing the right stack size requires profiling, as the docs honestly acknowledge. Too large and you waste stack space, too small and you don't benefit. The spill_to_heap behavior is automatic and correct, but understanding when it happens requires some performance awareness. Version 2.0 alpha brings const generics which eliminates some type verbosity, though being on alpha means exercising appropriate caution for production use.
Best for: Performance-sensitive code with collections that are usually small but occasionally grow, where heap allocation overhead matters.
Avoid if: You need collections that are consistently large, or cannot tolerate the stack space overhead of inline storage.
Drop-in Vec replacement with excellent ergonomics and stack optimization
The documentation is thorough with practical examples showing the key performance tradeoffs. Error messages are standard Rust fare since it integrates seamlessly with the type system. IDE support is excellent - autocomplete works perfectly because it implements the same traits as Vec. The spill_to_heap behavior is transparent and automatic, which is exactly what you want.
One gotcha is choosing the right inline capacity - too large and you waste stack space, too small and you lose the optimization. The docs could use more guidance on profiling and tuning this. Also, be mindful that moving large SmallVecs can be expensive if they haven't spilled to heap yet, though this is documented.
Best for: Collections with predictable small sizes (typically <32 items) where you want to avoid heap allocations without changing API surface.
Avoid if: Your collections regularly exceed a few dozen items or you need guaranteed consistent move performance regardless of size.
Sign in to write a review
Sign In