4 HN users recommended this talk4 months2018–2026score 4
Years with an HN recommendation, 2007–2026
HN returns to it as the go-to talk on string internals, small string packing and why small percentage optimizations matter at scale.
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.
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]
Facebook engineer on std::string internals and optimisation
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.
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%).
Why small percentage optimisations matter at scale
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] ).
Explains Facebook's motivation for replacing std::string with its own library
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
Cited on small string optimisation and memory overhead
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?
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]
Mentions page reuse behavior discussed in the talk
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]
Video list and Hacker News comment labels from HackerTube (prompted by @karpathy), released under ODC-By 1.0, built on the open-index/hacker-news archive. Hacker News data is provided by Y Combinator; comments remain the work of their authors. Video titles, channel names and thumbnails belong to their creators and are shown via YouTube. HackerTube Watch is an unofficial edition. Data export of 2026-10-31.
11 Hacker News comments
From the HN archive; up to 20 kept per video, favoring different commenters. Recommendations first.
Read more
Citations, criticism and jokes
Read more