Instructions
libc++ has a new optional ABI where std::vector stores len and cap instead of pointers which yields significantly better results when hardening is enabled, and "positive or neutral impact on run-time" without hardening
Adding a size-based vector to libc++’s unstable ABI
tl;dr We can significantly improve the runtime performance of std::vector by changing its representation from three pointers to one pointer and two integers. This document explains the details of this change, along with the justifications for making it.
There was #2574 but the benchmarks there were flawed and not cover all cases like different element sizes. In real code there are a lot of cases where std::vector<some_struct> is used and the struct size is unlikely to be a power of 2. In this case size() would need a multiplication, usually by a small number that fit into the immediate field of the instructions, or can be split into LEA or SHIFT/ADD series. In the traditional pointer-based it's a division by some number that will be converted into multiplication by a large "random" number that may need multiple instructions to construct
It would be nice if this alternative layout can be added
Instructions
libc++ has a new optional ABI where std::vector stores len and cap instead of pointers which yields significantly better results when hardening is enabled, and "positive or neutral impact on run-time" without hardening
There was #2574 but the benchmarks there were flawed and not cover all cases like different element sizes. In real code there are a lot of cases where
std::vector<some_struct>is used and the struct size is unlikely to be a power of 2. In this casesize()would need a multiplication, usually by a small number that fit into the immediate field of the instructions, or can be split into LEA or SHIFT/ADD series. In the traditional pointer-based it's a division by some number that will be converted into multiplication by a large "random" number that may need multiple instructions to constructIt would be nice if this alternative layout can be added