-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Currently, our basic_string implementation can store up to 15 narrow characters, or 7 wide characters, before dynamically allocating memory:
Lines 2134 to 2135 in 58bb49d
| // length of internal buffer, [1, 16]: | |
| static constexpr size_type _BUF_SIZE = 16 / sizeof(value_type) < 1 ? 1 : 16 / sizeof(value_type); |
Lines 2185 to 2196 in 58bb49d
| union _Bxty { // storage for small buffer or pointer to larger one | |
| _Bxty() {} // user-provided, for fancy pointers | |
| ~_Bxty() noexcept {} // user-provided, for fancy pointers | |
| value_type _Buf[_BUF_SIZE]; | |
| pointer _Ptr; | |
| char _Alias[_BUF_SIZE]; // TRANSITION, ABI: _Alias is preserved for binary compatibility (especially /clr) | |
| } _Bx; | |
| size_type _Mysize; // current length of string | |
| size_type _Myres; // current storage reserved for string |
We should consider retuning this optimization, given platform evolution over the last 20 years.
@BillyONeal commented: "Note that libc++'s implementation is a full pointer narrower than ours and stores up to 22 characters instead of 15; optimally small."
Related note: std::function's Small Functor Optimization was retuned before VS 2015 froze binary compatibility, using the heuristic that a function object storing a std::string should be considered small (regardless of architecture or debug mode). We don't necessarily have to retune std::function again, but we should at least check that the heuristic is still satisfied.
Also tracked by Microsoft-internal VSO-154236 / AB#154236.
vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.