Skip to content
Tech News
← Back to articles

A deep dive into SmallVector:push_back

read original more articles
Why This Matters

This article highlights recent optimizations in LLVM's SmallVector::push_back operation, particularly for trivially-copyable types, which are critical for performance in many C++ applications. The improvements focus on reducing unnecessary register saves and stack operations, leading to faster code execution and more efficient use of resources, ultimately benefiting both compiler developers and end-users by enabling more performant software.

Key Takeaways

tl;dr This blog post describes a recent SmallVector::push_back optimization for approximately trivially copyable element types.

SmallVector is LLVM's most-used container, and push_back its hot operation. For the trivially-copyable specialization the fast path should be fast.

1

2

3

void f (llvm::SmallVectorImpl< int > &v, int x) { v. push_back (x); }

clang -S --target=x86_64 -O2 -DNDEBUG a.cc generates:

... continue reading