HackerTube
HomeLongsLikedHistoryWatch laterCategoriesPlaylistsSettings

CppCon 2016: Nicholas Ormrod “The strange details of std::string at Facebook"

CppCon4 HN recommenders · recommended in 4 months, 2018-2026
YouTube
122K views · 10 years ago · talk · evergreen

Nicholas Ormrod's CppCon 2016 talk on how Facebook optimizes std::string with its open-source replacement fbstring. It covers storage layout tradeoffs, small string optimization and memory allocation behavior.

HN returns to it as the go-to talk on string internals, small string packing and why small percentage optimizations matter at scale.

C, C++, Rust, Go & systems languagesSoftware performance & optimization#std::string#fbstring#smallstringoptimization#memoryallocation#cppcon

11 comments from Hacker News

@def-pri-pub2026 · in “Faster Asin() Was Hiding in Plain Sight”

You'd be surprised how it actually is worth the effort, even just a 1% improvement. If you have the time, this is a great talk to listen to: ▶ this video For a little toy ray tracer, it is pretty measly. But for a larger corporation (with a professional project) a 4% speed improvement can mean MASSIVE cost savings. Some of these tiny improvements can also have a cascading effect. Imagining finding a +4%, a +2% somewhere else, +3% in neighboring code, and a bunch of +1%s here and there. Eventually you'll have built up something that is 15-20% faster. Down the road you'll come across those optimizations which can yield the big results too (e.g. the +25%).

RecommendsView on HN
@sqrt_12025 · in “Writing into Uninitialized Buffers in Rust”

I don't believe they are allocating 128 bytes, or accessing out of bounds memory. He explicitly states 128byte filename allocates 129 bytes. ▶ this video

CitesView on HN
@sqrt_12025 · in “Writing into Uninitialized Buffers in Rust”

It was from C++con 2016 - Facebook take on small strings ▶ this video I believe it is about a page that was conditionally returned to the kernel.

CitesView on HN
@D4ckard2024 · in “Fixing C Strings”

Yes, there are really cool packing techniques. See this talk for example: ▶ this video I don't include the null-terminator because I use this type in my own environment where I never use null-terminated strings so there is no need for it.

RecommendsView on HN
@jiggawatts2024 · in “Algorithms for Modern Hardware”

The FAANGS certainly have people doing this kind of work. For example, Andrei Alexandrescu has a bunch of keynote talks at CPPCon where he talks about 1-4% speed optimisations he makes to the std library at Facebook. link I also like the talk by Nicholas Ormrod “The strange details of std::string at Facebook": ▶ this video

RecommendsView on HN
@SkiFire132024 · in “The C bounded model checker: criminally underused”

At least Linux does this, and it is not a security hole because it only reuses pages with memory of the current process (as in the worst case you end up reading data from some other part of your program, but not other programs). And yes, it does happen in practice, most famously it has been mentioned in the "The strange details of std::string at Facebook" talk at CppCon 2016 ▶ this video

CitesView on HN
@nyanpasu642023 · in “Why Async Rust?”

Can you have the runtime run a job every second, to trim thread stack depths and return memory to the kernel (whatever was meant by ▶ this video ) while holding a FFI mutex (or a sharded one), and have every C function call first lock the mutex and expand the stack to the necessary depth?

CitesView on HN
@jiggawatts2023 · in “Analyzing multi-gigabyte JSON files locally”

You're all massively underestimating the memory requirements of a parsed data structure, which is very entertaining to watch. There's this rule-of-thumb that most programmers are wrong about performance costs by at least a couple of orders of magnitude, and it's on full display here. In most languages, dynamically allocated variable-sized objects have a minimum overhead of two pointer-sized fields: a pointer and a length. On a 64-bit platform, that's 16 bytes before you actually start having any data. Next, depending on the allocator used, the requested data size is probably rounded up, either to the next power of 2, or there may be a minimum allocation size of 1 pointer. That's "safe" on machines that can't do misaligned (byte-granularity) referencing directly from memory. Last but not least, most heap-based allocators have some "bookkeeping" overheads. Similarly, interpreted languages also have their internal "object" metadata overheads. Typically this is 1 or 2 extra pointers (+8 or +16 bytes). Assuming 24-48 bytes for all variable-length values is actually a pretty safe bet! There are exceptions: Unusually, C skips the 'length' value for strings by using null-termination, so C strings are often just 16 bytes (8 for the pointer, and 8 for the allocated object on the heap, assuming some sort of small-object optimisation is going on). The approach in C++ is to use "small string optimisation" where the string values are inlined into the std::string structure itself. This work

CitesView on HN
@pjscott2020 · in “Libc++'s Implementation of std::string”

I think this is the talk you're referring to. If not, it's still definitely worth a watch: ▶ this video

RecommendsView on HN
@GolDDranks2018 · in “Pointers Are Complicated, or What’s in a Byte?”

I'm not going to take the responsibility whether it's correct or not - here's the talk I learned it from: ▶ this video

CitesView on HN
@3uclid2018 · in “Show HN: SuperString – A fast and memory-optimized string library for C++”

Side note: FB also developed a string library to replace std::string ( link ). Here's a video from explaining the motivation behind the project ( ▶ this video ).

CitesView on HN
Stephan T. Lavavej “Floating-Point <charconv>: Making Your Code 10x Faster With C++17's Final Boss”1:00:17

Stephan T. Lavavej “Floating-Point <charconv>: Making Your Code 10x Faster With C++17's Final Boss”

CppCon
41K views • 7 years ago
CppCon 2016: Chandler Carruth “High Performance Code 201: Hybrid Data Structures"55:49

CppCon 2016: Chandler Carruth “High Performance Code 201: Hybrid Data Structures"

CppCon
119K views • 10 years ago
CppCon 2018: G. Nishanov “Nano-coroutines to the Rescue! (Using Coroutines TS, of Course)”1:04:26

CppCon 2018: G. Nishanov “Nano-coroutines to the Rescue! (Using Coroutines TS, of Course)”

CppCon
40K views • 8 years ago
CppCon 2014: Chandler Carruth "Efficiency with Algorithms, Performance with Data Structures"1:13:41

CppCon 2014: Chandler Carruth "Efficiency with Algorithms, Performance with Data Structures"

CppCon
235K views • 12 years ago
CppCon 2015: Andrei Alexandrescu “std::allocator...”1:12:27

CppCon 2015: Andrei Alexandrescu “std::allocator...”

CppCon
196K views • 11 years ago
CppCon 2015: Sean Parent "Better Code: Data Structures"1:04:00

CppCon 2015: Sean Parent "Better Code: Data Structures"

CppCon
106K views • 11 years ago
C++Now 2018: You Can Do Better than std::unordered_map: New Improvements to Hash Table Performance1:30:53

C++Now 2018: You Can Do Better than std::unordered_map: New Improvements to Hash Table Performance

CppNow
63K views • 8 years ago
CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”1:39:25

CppCon 2016: Herb Sutter “Leak-Freedom in C++... By Default.”

CppCon
149K views • 10 years ago
CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid”1:15:46

CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid”

CppCon
178K views • 9 years ago
2013 Keynote: Chandler Carruth: Optimizing the Emergent Structures of C++1:33:02

2013 Keynote: Chandler Carruth: Optimizing the Emergent Structures of C++

CppNow
34K views • 13 years ago
Can C++ be 10x Simpler & Safer?  - Herb Sutter - CppCon 20221:54:00

Can C++ be 10x Simpler & Safer? - Herb Sutter - CppCon 2022

CppCon
277K views • 3 years ago
CppCon 2019: Emery Berger “Mesh: Automatically Compacting Your C++ Application's Memory”36:10

CppCon 2019: Emery Berger “Mesh: Automatically Compacting Your C++ Application's Memory”

CppCon
15K views • 7 years ago
CppCon 2014: Mike Acton "Data-Oriented Design and C++"1:27:46

CppCon 2014: Mike Acton "Data-Oriented Design and C++"

CppCon
862K views • 12 years ago
CppCon 2017: Louis Brandy “Curiously Recurring C++ Bugs at Facebook”52:01

CppCon 2017: Louis Brandy “Curiously Recurring C++ Bugs at Facebook”

CppCon
158K views • 9 years ago
CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”59:34

CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”

CppCon
137K views • 9 years ago
CppCon 2019: Matt Godbolt “Path Tracing Three Ways: A Study of C++ Style”55:42

CppCon 2019: Matt Godbolt “Path Tracing Three Ways: A Study of C++ Style”

CppCon
77K views • 7 years ago
CppCon 2018: Hana Dusíková “Compile Time Regular Expressions”54:48

CppCon 2018: Hana Dusíková “Compile Time Regular Expressions”

CppCon
14K views • 8 years ago
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"1:29:54

CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"

CppCon
188K views • 11 years ago
CppCon 2017: Chandler Carruth “Going Nowhere Faster”1:00:58

CppCon 2017: Chandler Carruth “Going Nowhere Faster”

CppCon
113K views • 9 years ago
C++ Exceptions for Smaller Firmware - Khalil Estell - CppCon 20241:24:36

C++ Exceptions for Smaller Firmware - Khalil Estell - CppCon 2024

CppCon
23K views • 1 year ago