Size-based representation for std::vector
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
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 https://github.com/microsoft/STL/issues/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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the linked LLVM libc++ ABI proposal and the prior microsoft/STL issue 2574, then identify the STL implementation and test areas affected by an alternative std::vector representation. Done means the proposed size-based layout is implemented with appropriate ABI coverage and its performance and behavior are validated across element sizes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100