<story><title>Libc++&apos;s Implementation of std::string</title><url>https://joellaity.com/2020/01/31/string.html</url></story><parent_chain><item><author>dylanmclark</author><text>Reminds me of a talk a few years ago about Facebook&amp;#x27;s internal implementation of std::string. They do the same short string optimization, but Facebook manages to outperform this implementation by storing 24 bytes (vs 23) in &amp;quot;short string mode&amp;quot;.&lt;p&gt;IIRC, Facebook achieves this by using the last byte as the flag byte. To signify short string mode, this flag is set 0. This allows it to also serve as the null terminator. Tricky!</text></item></parent_chain><comment><author>lbrandy</author><text>hey i&amp;#x27;ve worked on this stuff for awhile at fb.&lt;p&gt;One important update is that the primary rationale for us, at the time, to change std::string&amp;#x27;s implementation to `fbstring` was to get SSO. We got huge perf wins for having SSO on std::string. (small string optimization for those unfamiliar with the initialism).&lt;p&gt;This, at the time, was a violation of the standard. By wording, SSO was not standard compliant.&lt;p&gt;Once the standard was changed (as of C++11) so that std::strings could have SSO, we removed our patches on the standard library and now use &amp;quot;vanilla&amp;quot; std::string (from libstdc++). We still have `folly::fbstring` for people who want that implementation (which is smaller, and has more in-situ capacity, because of various cleverness detailed in that talk), but it&amp;#x27;s no longer our `std::string`.&lt;p&gt;For reference: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;facebook&amp;#x2F;folly&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;folly&amp;#x2F;FBString.h&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;facebook&amp;#x2F;folly&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;folly&amp;#x2F;FBString...&lt;/a&gt;</text></comment>
<story><title>Libc++&apos;s Implementation of std::string</title><url>https://joellaity.com/2020/01/31/string.html</url></story><parent_chain><item><author>dylanmclark</author><text>Reminds me of a talk a few years ago about Facebook&amp;#x27;s internal implementation of std::string. They do the same short string optimization, but Facebook manages to outperform this implementation by storing 24 bytes (vs 23) in &amp;quot;short string mode&amp;quot;.&lt;p&gt;IIRC, Facebook achieves this by using the last byte as the flag byte. To signify short string mode, this flag is set 0. This allows it to also serve as the null terminator. Tricky!</text></item></parent_chain><comment><author>pjscott</author><text>I think this is the talk you&amp;#x27;re referring to. If not, it&amp;#x27;s still definitely worth a watch:&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.youtube.com&amp;#x2F;watch?v=kPR8h4-qZdk&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.youtube.com&amp;#x2F;watch?v=kPR8h4-qZdk&lt;/a&gt;</text></comment>