Improving Performance in std::vector: The Little Things
The article discusses the performance limitations of std::vector and explores a simple API change that can significantly improve its performance. While std::vector is often considered the default container due to its good baseline performance, various non-standard reimplementations have emerged over time to address specific performance considerations. However, these changes cannot be merged into std::vector without significant modifications. The article introduces the concept of push_back_unchecked, a function that inserts a new element into the vector without checking for capacity, and demonstrates its impact on performance through benchmarks. By using push_back_unchecked, developers can achieve a performance improvement of 10+%. The article also provides benchmark results for different compilers, including MSVC, GCC, and Clang. This API change can be particularly useful for developers looking to optimize their code and improve the performance of std::vector in their applications.