
SSO-23: Memory-Optimal Small String Optimization Implementation for C++ - vmorgulis
https://github.com/elliotgoodrich/SSO-23
======
lultimouomo
I have to say that from the document I get the feeling that clang makes the
best compromise; their implementation seems much more clear and linear to me,
and it looses just on character in short mode.

Benchmarking these kind of things is always difficult, because you can rig
(voluntarily or not) microbenchmarks to go either way, and the performance
gains are easily lost in real world usage.

------
ot
Folly fbstring has the same trick, and it's a std::string compliant
implementation used in production at Facebook.

[https://github.com/facebook/folly/blob/master/folly/docs/FBS...](https://github.com/facebook/folly/blob/master/folly/docs/FBString.md#storage-
strategies)

------
apaprocki
Similarly, Bloomberg's bsl::string (std::string) performs SSO as well and is
used throughout Bloomberg's stack.

[https://github.com/bloomberg/bde/blob/master/groups/bsl/bsls...](https://github.com/bloomberg/bde/blob/master/groups/bsl/bslstl/bslstl_string.h)

------
rwmj
You can make this better by not storing the size at all, even for the long
strings: [https://rwmj.wordpress.com/2016/01/08/half-baked-ideas-c-
str...](https://rwmj.wordpress.com/2016/01/08/half-baked-ideas-c-strings-with-
implicit-length-field/)

~~~
masklinn
That's not a better idea, and it stores the difference between size and
capacity which is exactly the trick SSO-23 uses in SSO.

------
twoodfin
mikeash has a great post on Apple's tagged pointer for NSString:

[https://www.mikeash.com/pyblog/friday-
qa-2015-07-31-tagged-p...](https://www.mikeash.com/pyblog/friday-
qa-2015-07-31-tagged-pointer-strings.html)

In that environment, you only have 60 bits to play with, so it's more
aggressive about varying encodings to fit in more common strings.

------
josteink
Unfortunate name. SSO is already an established term for "single sign on" used
in Login federation everywhere.

~~~
jmgao
The short string optimization is decades old.

~~~
b34r
Sure, but in terms of mindshare it's thoroughly eclipsed by single sign on.

~~~
yoklov
This definitely depends on who you're talking to.

