CppCon 2019: Chandler Carruth “There Are No Zero-cost Abstractions”
Why Hacker News recommends it
HN commenters cite it whenever zero-cost abstraction claims come up, especially for why unique_ptr is not free on some ABIs.
What it is
Chandler Carruth argues in a CppCon 2019 talk that C++ has no truly zero-cost abstractions. Using examples like unique_ptr, ABI constraints and compile-time costs, he shows that abstractions cost runtime, compile time or human effort.
Recommended by 7 HN commenters across 7 different months, 2020 to 2026.
What Hacker News said
Strong rec metalrain · 2022-03 · on “Tech talks don’t have to be boring”
Yes, tech talks don't need to be boring and I agree on many points on the post. But also not just 12 slides, more like hundreds of slides. One example I have is Chandler Carruths talk in CppCon 2019 "There Are No Zero-cost Abstrations" [this video] Chandler presents his point clearly and goes deep enough into the subject.
Recommends blux · 2020-02 · on “Move, simply”
The non-destructiveness of move semantics in C++ is very annoying. It causes for example `std::unique_ptr` to not be a zero-cost abstraction in all cases. See [this video] for a nice expose on this.
Recommends mehrdadn · 2020-09 · on “The problem with C”
With the caveat that I am NOT suggesting this justifies choosing C over C++, I just wanted to mention this talk about how "zero-cost abstraction" is an idealism, not necessarily a reality: [this video] That said, I tried to reproduce something similar, and it seems the issue only occurs in my example due to external linkage (adding 'static' fixes it)... but I can't claim this will always resolve the issue: [LINK]
Recommends tylerhou · 2020-10 · on “The AMD Radeon Graphics Driver Makes Up Roughly 10.5% of the Linux Kernel”
The other time that you saw it was also probably me. It's from this talk, which is about how a large amount of generated protocol buffer code at Google led to a quadratic increase in compile times: [this video] . TL;DW: The reasoning is because if you use a distributed build system, then your compile time is gated by the file with the longest compile time (tail latency). The more files you have, the greater chance that one of them takes a long time. When you generate source files, you tend to produce more files than if you didn't. Most users don't use a distributed build system to compile the kernel, so on further thought, in that case compile times probably scale closer to linear with the number
Recommends CountHackulus · 2021-08 · on “When zero cost abstractions aren't zero cost”
There are no zero cost abstractions. (According to Chandler Carruth, and he makes a convincing point). [this video]
Recommends kccqzy · 2022-09 · on “C++20, How Hard Could It Be”
> std::unique_ptr<Foo> doesn't have any overhead over Foo* in code where semantics is the same Not true. And you just refuted yourself by being up the ABI question. You should watch Titus Winters' presentation on this topic where he compiles code using unique_ptr and raw pointers, compares the assembler produced, and explains why unique_ptr has non-zero overhead. The overhead is indeed coming from the ABI. Google has been wanting the next C++ to break ABI but they didn't get enough votes in the standard committee. [this video]
Recommends TwentyPosts · 2023-07 · on “Scope-based resource management for the Linux kernel”
When it comes to the overhead issues of unique_ptr, I always think of this video here: [this video] At 26:50 he gets into how this relates to ABI, and how 'fixing' some of this would require a pretty severe ABI change, as well as destructive move semantics, which would require a severe change to how C++ works. I frankly don't understand C++ well enough to fully judge about all of this, but everything he says seems entirely solid, and showcases how unique_ptr is in fact not zero-cost, and can in fact be a significant performance trade-off when you really need that extra bit of performance. > Rust occasionally forces my hand considerably harder (e.g. RC<RefCell<..>> vs std::shared_ptr<>)) in the di
Cites leni536 · 2020-02 · on “ABI – Now or Never [pdf]”
The video: [this video] I wrote up a reddit post for a possible workaround for removing the overhead. It's standard C++, no ABI break is required. It's not without caveats though: [LINK]