It's hard to know how to take this given that their first example (function call overhead) seems deeply flawed -- you'd never have a 'compare' strings function take std::string by value. (Maybe const string& or string_view). Also, the alternative would have to have a destructor of some type (unless it is a string_view analog) to make it an apples to apples comparison.
the entire article rests on a shorter String that can be fit on registers reliably. If you have bytes in registers, it is not clear that passing bytes by value is "deeply flawed."
You'd never have a `compare(std::string a, std::string b)` function in your code base. It would make copies of the strings (and destroy them). So it seems to me the article is comparing their new thing to a straw man.
They made a C++ string type, let's call it "german_string", with sizeof(german_string) == 16. german_string can be in SSO mode (4 byte size field plus 12 SSO bytes) or in long string mode. In long string mode, they still use 4 bytes for the size, store no capacity (capacity is always equal to size), use another 4 bytes to always store the prefix of the string (this avoids a memory indirection in many cases when doing string comparisons), plus the pointer. Furthermore, a long string mode german_string can also act as a string_view or a string_view to ".rodata"; this is called the "string class". The string class is stored in two bits stolen from the 8 byte pointer.
6 comments
[ 3.2 ms ] story [ 23.8 ms ] threadThey made a C++ string type, let's call it "german_string", with sizeof(german_string) == 16. german_string can be in SSO mode (4 byte size field plus 12 SSO bytes) or in long string mode. In long string mode, they still use 4 bytes for the size, store no capacity (capacity is always equal to size), use another 4 bytes to always store the prefix of the string (this avoids a memory indirection in many cases when doing string comparisons), plus the pointer. Furthermore, a long string mode german_string can also act as a string_view or a string_view to ".rodata"; this is called the "string class". The string class is stored in two bits stolen from the 8 byte pointer.