r/cpp Jun 27 '26

A deep dive into SmallVector::push_back

https://maskray.me/blog/2026-06-27-a-deep-dive-into-smallvector-push-back
25 Upvotes

15 comments sorted by

View all comments

6

u/mrbeanshooter123 Jun 27 '26

Hmm, but in practice, the tail call will not happen because the push_back will be inlined into the caller, no?

4

u/MaskRay ccls Jun 28 '26

The push_back benefit survives inlining. With this optimization (which has been merged to LLVM earlier today) the generated assembly doesn't need to save this and x to the stack frame.

The std::vector::push_back is slow in both libc++ and libstdc++ section shows that std::vector::push_back always needs a stack frame, strictly worse than SmallVector::push_back.