The strange details of std::string at Facebook
summary
Shows concrete internals: GCC 4 uses a 25-byte global empty string plus copy-on-write with refcount-minus-one, while Facebook's fbstring uses a 24-byte struct with SSO storing up to 23 in-situ bytes and stores flags in low bits via JMalloc buckets. Replacing std::string at Facebook in 2012 yields a 1% performance win company-wide. Covers perf and perf counters, a cache-line–trashing c_str bug at a page boundary, the attempted removal of the null terminator, and tradeoffs after GCC5 switches to a 32-byte std::string with only 15-byte SSO.
AI-written summary · about
chapters (15)
- 0:00Introduction to std::string
- 1:06Why strings matter at Facebook
- 2:11How GCC implements std::string
- 5:32GCC string optimizations
- 6:39FB string vs GCC string
- 8:23Small string optimization in FB string
- 13:21Clang and Microsoft string implementations
- 14:45Performance comparison of FB and GCC strings
- 17:15Replacing standard string with FB string
- 19:00Removing the null terminator
- 21:08The const c_str() problem
- 23:17The most complex bug in FB string
- 26:05GCC 5’s new string layout
- 29:16GCC 5 vs FB string trade-offs
- 30:19Conclusion and future of std::string
related talks
59mSoftware Engineering Is About Tradeoffs
01h 21mC++ MythBusters
36mInterfaces Matter
01h 12mComparison of C++ Performance Optimization Techniques for C++ Programmers
50mHow to break an ABI and keep your users happy
01h 00m“Evolving array_view and string_view for safe C++ code"
35mWhat C++ developers should know about globals (and the linker)
02h 25mHow to Keep C++ Binaries Small - Techniques for C++ Optimization
