A deep dive into SmallVector:push_back
- Programming
- Performance
- Compilers
- Developer Tools
The post walks through `SmallVector::push_back` at the assembly level and uses it as a case study in why a simple-looking C++ operation can compile into code with avoidable reloads, awkward slow-path setup, and architecture-specific tradeoffs. You do not need to care about `SmallVector` itself to get the point. This is really about how aliasing rules, calling conventions, and compiler decisions shape the cost of tiny container operations that end up everywhere in performance-sensitive code.
If a hot path depends on tiny container operations, inspect the generated code instead of assuming the optimizer handled it. Also treat `reserve`-style APIs carefully, because a vague capacity contract can turn a small micro-optimization into worse long-run growth behavior.
- maskray.me
- Discuss on HN