Jank's new persistent string is fast (2023)
jank-lang.org
jank-lang.org
It is not at all clear to me that the SSO is worth it if you don't need this terminator. C++ has no real choice, it is wedded to C-style zero terminated strings and so the SSO is necessary to be competitive, but if you're rejecting that surely it's time to entirely re-evaluate this data structure ?
[On a typical modern 64-bit computer] An empty Rust std::String is 24 bytes, exactly the same as the Clang libc++ std::string as somewhat smaller than an MSVC or GCC std::string
Most strings are "pretty small" but that's relative. SSO often gives you 15 characters, so the string "http://news.ycombinator.com/" is far too big, so is my full name, my work email address, a credit card number, and so on.
The biggest pay off seems to be that empty string, in Rust's model it's free, in C++ it could not be free without SSO.
That's what libstdc++ did in its old refcounted variant, for example.
And no, you don't need refcounting.
So no need to worry so much about 15 or 16 bytes SSO, or the empty string case (which as the other commenter points out you can easily model with a statically allocated "").