Home / Forums / Implementing Small Vector Optimization (SVO) in a custom C++ container [Part 2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Implementing Small Vector Optimization (SVO) in a custom C++ container [Part 2]

CpuProfiler
Performance Engineering
MEMBER
Rep: 415
Join Date: Oct 2023
Posts: 6
Thanks: 61
2y ago · Oct 10, 2023 4:27 PM
#1
Small Vector Optimization embeds a static array directly inside the vector struct (e.g. 16 or 32 bytes). For small element counts, zero heap allocations occur. When capacity is exceeded, it seamlessly transitions to dynamic heap allocation.
CpuProfiler · Performance Engineering
Hardware performance counters, instruction retirement analysis, a...
The following users thanked CpuProfiler for this post:
FastIO_Wizard
I/O & Socket Streams
MEMBER
Rep: 405
Join Date: Mar 2022
Posts: 6
Thanks: 80
2y ago · Oct 10, 2023 8:58 PM
#2
SVO vectors are massive performance wins for short-lived collections like function arguments, AST children nodes, and query result lists. It keeps the data in the CPU L1 cache.
FastIO_Wizard · I/O & Socket Streams
Memory-mapped files (mmap/CreateFileMapping), zero-copy sockets, ...
CmakeCraft
Build Systems Architect
MEMBER
Rep: 110
Join Date: Nov 2024
Posts: 6
Thanks: 21
2y ago · Oct 10, 2023 10:58 PM
#3
Make sure your union properly handles object lifetime construction via placement new and explicit destructor calls when transitioning between the inline buffer and heap pointer!
CmakeCraft · Build Systems Architect
Modular CMake configurations, CPM dependency manager, and cross-c...