4 ms·
SSO-23: Memory-Optimal Small String Optimization Implementation for C++
- josteink 11y agoUnfortunate name. SSO is already an established term for "single sign on" used in Login federation everywhere.
- ot 11y agoFolly 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/FBString.md#storage-strategies https://github.com/facebook/folly/blob/master/folly/docs/FBS...
- lultimouomo 11y agoI 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.
- twoodfin 11y agomikeash has a great post on Apple's tagged pointer for NSString: https://www.mikeash.com/pyblog/friday-qa-2015-07-31-tagged-pointer-strings.html https://www.mikeash.com/pyblog/friday-qa-2015-07-31-tagged-p... 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.
- rwmj 11y agoYou 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-strings-with-implicit-length-field/ https://rwmj.wordpress.com/2016/01/08/half-baked-ideas-c-str...
- masklinn 11y agoThat's not a better idea, and it stores the difference between size and capacity which is exactly the trick SSO-23 uses in SSO.
- apaprocki 11y agoSimilarly, 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/bslstl/bslstl_string.h https://github.com/bloomberg/bde/blob/master/groups/bsl/bsls...