[llvm-dev] PSA: SmallVector<T> Just Works

Sean Silva via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 7 13:32:29 PST 2020


TL;DR: SmallVector now chooses a default "N", and we recommend using that
default.

We hope that this will
- Avoid semi-arbitrary choices for the "N" parameter.
- Save you extra edit/compile cycles for forgotten "N" parameters.
- Avoid some of the pathological cases of SmallVector use (like
sizeof(SmallVector) becoming excessively large)

The programmer's manual has been updated, and now reads

In the absence of a well-motivated choice for the number of inlined
elements N, it is recommended to use SmallVector<T> (that is, omitting the N).
This will choose a default number of inlined elements reasonable for
allocation on the stack (for example, trying to keep
sizeof(SmallVector<T>) around
64 bytes).

https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h

We haven't planned any big refactoring to use the new default, so we are
expecting it to catch on organically in new code / code reviews /
refactorings.

Enjoy! :)

For historical reference: This landed in https://reviews.llvm.org/D92522
after much discussion on the list
<https://groups.google.com/g/llvm-dev/c/Z-VwNCTRGSg/m/fYi0JHhzAwAJ>
and an earlier
attempt at a patch <https://reviews.llvm.org/D90884> which went back and
forth on various ideas, including more general aspirations for
SmallVector's evolution.

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201207/deb5f741/attachment.html>


More information about the llvm-dev mailing list