[PATCH] D90884: [SmallVector] Add a default small size.

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 10 13:01:43 PST 2020


rnk added a comment.

Standing back a bit, I think most C++ programmers use std::vector and call it a day, so perhaps zero really is the sensible default. Are those programmers missing out and doing too many heap allocations? I tend to think not. I think setting an inline storage size without profiling is often a premature optimization. I think it's probably a lot easier to notice small, short-lived vectors in a profiler than it is to notice excessive memory usage due to poorly tuned SmallVectors on the heap.

I think "SmallVector" doesn't really mean "vector with inline storage". It really means "LLVM's optimized vector reimplementation", see the usage of uint32_t sizes and capacities.

I think it makes sense to add a low, default size to SmallVector. Both this heuristic and zero seem fine to me. This makes it easy to profile, find slow, small vector heap allocations, and tune the size later without changing APIs from std::vector to SmallVector.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90884/new/

https://reviews.llvm.org/D90884



More information about the llvm-commits mailing list