CppCon 2019: Chandler Carruth “There Are No Zero-cost Abstractions”

preview_player
Показать описание



C++ is often described as providing zero-cost abstractions. Libraries offer up facilities documented as such. And of course, users read all of these advertisements and believe that the abstractions they are using are truly zero-cost.

Sadly, there is no truth in advertising here, and there are no zero-cost abstractions.

This talk will dive into what we mean by "zero-cost abstractions", and explain why it is at best misleading and at worst completely wrong to describe libraries this way. It will show case studies of where this has led to significant problems in practice as libraries are designed or used in unscalable and unsustainable ways. Finally, it will suggest a different framing and approach for discussing abstraction costs in modern C++ software.

Chandler Carruth
Google


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

"Each abstraction must provide more benefit than cost" - That is something to live by, and it's not only applicable to C++.

Attlanttizz
Автор

Chandler is one of the better speaker at CppCon: Interesting, entertaining, non-standard and considering real questions.

mathieu
Автор

Indeed, C++ provides brilliant solutions to the problems it itself introduced.

tomaszstanislawski
Автор

I think the talk is great. To be fair to the "unique_ptr<T> is zero-cost compared to raw pointers" crowd, they are always emphasizing that it is not common to frequently change ownership. They generally show how terrible it is for performance to overuse passing shared pointers around, and don't focus on passing unique pointers around everywhere because that doesn't happen that commonly, and where it does, it could be a disaster if you misused raw owning pointers, which would be fairly easy to do.

jvsnyc
Автор

Finally somebody who thinks about what code does and not just how code looks.

lepidoptera
Автор

Move destruction is an interesting thought. Rust works the same way. However, current C++ allows us to move member class variables and that would be a breaking change.

zechordlord
Автор

Liked the Google pun: Larry&Sergey Protobuf Moving Co. (established 1998).

erkinalp
Автор

Always a great talk with Chandler. You'll always find yourself relating to him or in a deep state of introspection as he flips your perspective on your head.

kenneth_romero
Автор

I've always understood that Zero-cost abstractions refer to abstractions that add no overhead to a solution built by hand. Especially after optimization, languages with smart enough semantics can have abstractions that are as efficient than attempts at assembly would be (and be way easier to maintain).

jeffvandyke
Автор

I tested Chandler's unique_ptr example myself, and I did see changes with noexcept, but if I remove noexcept and just add the rvalue references, the noexcept doesnt make a difference.

BigPapaMitchell
Автор

Zero-cost refers to no additional instructions or ram usage. Readability and compile time are not considered cost in that turn of phrase.

Dziaji
Автор

I really find what Chandler is telling very informative, thanks very much. However, I always have a problem with his presentations. It always sounds like everything is bad with C++, he says don't use this and don't use that, OMG it is so bad. I agree fully, hence the arguments are absolutely convincing, but there is almost never any alternative coming. Too many people who watched his presentations now implementing their own maps and unique/shared pointers etc., which are horrible. They invest endless time to implement something sometimes even worse, than in STL, arguing that Chandler said, that the standard implementation is bad. I really had a discussion with somebody, who refused to return unique_ptr from a factory class, going for raw pointer instead, just because he was so impressed by Chandlers talk. The conclusion was, that RAII is bad, because it adds overhead. What is it all about? How should this help C++ to evolve? What about avoiding premature optimization? Why not explicitly presenting this topic as an optimization one? I think it is clear that any abstraction layer costs us somewhere something, but pushing people not to use language features and STL is a wrong way in my opinion.

scorp
Автор

always intrigued with this dude's talk;

shahmiBro
Автор

I have encountered cases at work where the time cost of functions over using goto was sufficiently high that I was unable to use functions. There is a cost, even for very basic abstractions.

diltsman
Автор

I always understood the "cost" in "zero-cost abstractions" to be the cost of including them in the language, but not using them. Not the costs of actually using them. Even functions have a small cost of stack traffic, the calling convention limiting usable registers near a call site, etc.

alexreinking
Автор

I strongly disagree with the idea that it is harder to refactor generated code. If you are generating, say, a design pattern of some kind, it's a lot easier to refactor the generator than actually take the pattern implemented in various places in your code and refactor that to some other pattern.

DmitriNesteruk
Автор

Damn. I always tought unique_ptr and small objects are passed in registers. Doh, not true, because because unique_ptr has non-trivial destructor is passed via memory. Very sad. Definitively we need ABI change for this for common standard pointers on which we know move semantics.

movaxh
Автор

This is a brilliant talk and it does remind me of what Rust is doing to some degree. Really interesting and thought provoking

Dominik-K
Автор

31:20 I don't think switching your focus between functions is any different from switching between blocks of code!

anasouardini
Автор

Author + Title is enough for me to know that this is a thumbs-up :) Now to listen to the wisdom...

JasonRennie