No video

Great C++ is_trivial: trivial type traits - Jason Turner - CppCon 2023

  Рет қаралды 19,546

CppCon

CppCon

Күн бұрын

cppcon.org/
---
Great C++ is_trivial: trivial type traits - Jason Turner - CppCon 2023
Jason Turner - CppCon 2023
github.com/Cpp...
There are many ways to initialize an object in C++, and much time spent analyzing the efficiency of the many options. We then think and rethink and overthink how to avoid copies and if a `std::move` would be more efficient in a certain case.
But if we understand what it means for a type to be trivial most of these questions now become meaningless. We can get all of the efficiency we could hope for, and probably more.
We will look at the trivial type traits, what they mean, and how they affect our code. Will will then examine the benefits of using trivial types and the impact on performance.
---
Jason Turner
Jason is host of the KZbin channel C++Weekly, co-host emeritus of the podcast CppCast, author of C++ Best Practices, and author of the first casual puzzle books designed to teach C++ fundamentals while having fun!
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZbin Channel Managed by Digital Medium Ltd: events.digital...
---
Registration for CppCon: cppcon.org/reg...
#cppcon #cppprogramming #cpp

Пікірлер: 48
@sqw33k
@sqw33k 4 ай бұрын
Man, I absolutely love everything with Jason Turner in it. He's clear, he's concise and he's funny. ^^ Great guy!
@TheSulross
@TheSulross 3 ай бұрын
warning, though - this particular talk was very trivial
@rutabega306
@rutabega306 3 ай бұрын
Idk he took forever to get to content
@embedded_software
@embedded_software 4 ай бұрын
I see Jason Turner, I click. It’s as simple as that
@hampus23
@hampus23 4 ай бұрын
Me too
@nirajandata
@nirajandata 4 ай бұрын
unlike some conference talks, i find jason talks highly interactive
@jaybee9054
@jaybee9054 4 ай бұрын
Jason is a "CPP Superstar" 🌟
@_noisecode
@_noisecode 3 ай бұрын
I feel like after discussing triviality, it would have been interesting to see some examples about a trivial struct type that couldn't fit in a register, rather than just examples about int which is obviously always going to do the fast thing. If the point was supposed to be "see, triviality always does the fast thing and you don't have to think about it like you do with std::string," it would have helped to see how a large trivial struct interacts with RVO/explicit std::move. Returning in registers kind of renders RVO/std::move irrelevant/not applicable, as Jason even said, so it wasn't really an apples to apples comparison with the earlier std::string examples. For the record, for a large trivial struct, I believe the advice is mostly the same as std::string--don't explicitly std::move because that inhibits copy elision which you are likely to otherwise get. But--you don't have to spend as much time worrying about copy vs. move because they're equivalent anyway. The ultimate takeaway of the talk is that trivial types are faster to pass around your code because they don't have to do work in their SMFs. That is true, but as insights go, it's also kind of... trivial. Jason Turner is an engaging, genuinely likable, and overall just fantastic speaker as always.
@bobi97bg
@bobi97bg 3 ай бұрын
So what this basically boils down to is - use C-style structs. Not that I'm complaining.
@stefanalecu9532
@stefanalecu9532 Ай бұрын
Then go ahead and use C instead :)
@Muzzleflash1990
@Muzzleflash1990 4 ай бұрын
Debug performance is a substantial problem in C++, but I find it disheartening that there is being added special handling for the standard library inside the compiler kzbin.info/www/bejne/mKGpYn-BhqeaeLM. It elevates std code as something with special compiler support doing something that users cannot replicate in their own code.
@leonid998
@leonid998 4 ай бұрын
13:08 and other places, it would be useful to have the use_string declaration displayed, otherwize we are speaking without sufficient context.
@Reneg973
@Reneg973 2 ай бұрын
Regarding is_trivially_constructible: what is it good for? Any members should have default values, so I currently don't see a use case
@surters
@surters 4 ай бұрын
"This is keeping Ben awake tonight" while he reads the std. :)
@sanjaygatne1424
@sanjaygatne1424 4 ай бұрын
C++'s simple language construct is great puzzle for seasoned C++ user. Interesting for QA but ? for learning and productivity, debugging, safty and ...
@rutabega306
@rutabega306 3 ай бұрын
Tbh none of these were safety concerns. Worst case was a copy where you wanted to move.
@ugi612013
@ugi612013 4 ай бұрын
The fact that a developer needs to consider which of the options is better, is a defect in Cpp. The compiler should be able to optimize all to the best performance... I find these trick questions hilarious, cpp programers love these, while in fact a programer should worry about other stuff while the compiler does the optimizations achieving the same performance (and dont tell me it cant! See Rust)
@Einsteinium-abc99
@Einsteinium-abc99 4 ай бұрын
Just what I was thinking the whole time. 100% agree
@nyyakko
@nyyakko 4 ай бұрын
cool!
@kaosce
@kaosce 4 ай бұрын
I agree and that is also one of the directives of Python (see PEP20)
@japedr
@japedr 4 ай бұрын
There is no free lunch, designers of C++ had to make a lot of trade offs and every apparently nonsensical issue has very likely a well motivated reasoning behind it. I really like Rust, but for example I find it irritating that many numerical algorithms are imposible for the compiler to optimize without resorting to "unsafe" and/or unergonomic use of the language. This is the case when any random access to an array has an implicit bounds check and I am "mathematically" certain will never trigger, but obviously the compiler can see so far; this is a waste of extra instructions (polluting the I-Cache), many of which are branches (polluting the branch predictor cache), which makes the whole program incrementally slower: even if each pessimisation is insignificant in isolation, many of them can add up into something noticeable.
@attrition0
@attrition0 4 ай бұрын
But then how would you run a successful cottage industry of consultants coming in to teach C++ to C++ developers?
@AntonioNoack
@AntonioNoack Ай бұрын
Start at 3:32
@Debrugger
@Debrugger 3 ай бұрын
This language is insane, only python keeps me more on my toes every time I write something non trivial in it.
@nicholaskomsa1777
@nicholaskomsa1777 3 ай бұрын
if you are unsure if you have copies or moves and their optimization, you have probably factored wrongly. That said, you act as if const/auto& is not a thing. Furthermore, the amount of contrived invention required to proceed to create this talk seems to be a systemic problem
@terragame5836
@terragame5836 4 ай бұрын
44:55 The -O0 flag actually means "deliberately deoptimize", rather than "don't bother optimizing". -O1 is the default, and I'm pretty sure it would still result in a trivial return for that function.
@_noisecode
@_noisecode 3 ай бұрын
This is fully not true. The default for both clang and gcc is -O0, and it just provides no optimization, for the fastest possible compile speed and the easiest debugging experience. There would be no good reason for a compiler to have an option to spend time making your code worse. std::move calls do disappear at -O1, but that's because a small amount of optimization is applied at -O1.
@VickyGYT
@VickyGYT 5 күн бұрын
Post c++14 all you have done is add more interview questions than improving/ simplifying language. Day by day it’s getting uglier
@DerHirni
@DerHirni 4 ай бұрын
24:20 to skip the C++ quiz and get to the actual topic
@olivier4263
@olivier4263 4 ай бұрын
it's not a quiz, it's to understand the language better bruh
@agentstona
@agentstona 3 ай бұрын
This talk was LAME the guy spent firts 15 minutes playing trivia ... I mean this was more of a Come lets play trivia than a talk ...
@hellwolf4liberty
@hellwolf4liberty 4 ай бұрын
I started learning C++ in the early 2000s. I am appalled to see today's C++. At some point, we might need to decide whether to indulge in playing our own games or rethink what it means to programming.
@xarcaz
@xarcaz 4 ай бұрын
ok boomer
@sqw33k
@sqw33k 4 ай бұрын
What exactly about today's C++ are you appalled by?
@aniketbisht2823
@aniketbisht2823 4 ай бұрын
Would you mind sharing some of your grudges regarding C++ specific to this talk?
@sirhenrystalwart8303
@sirhenrystalwart8303 4 ай бұрын
I agree. There is too much magic that may or may not happen. Just creating a constructor is fraught with peril. And compilers do a terrible job of at giving any sort of insight into what they did or didn't do. Hidden member functions are one of the worst ideas of c++. Even worse is that hidden member functions can be implicitly deleted by doing seemingly innocuous things. Worse than that is that instead of a compile error, you often just end up with sub-optimal code where the class is used (e.g., you get a copy instead of a move). It would be much better if we required the developer to explicitly delete those member functions in order for the code to compile instead of having the compiler do it automatically. All of this just smacks of a optimizing for characters written instead of maintainability.
@bdafeesh
@bdafeesh 4 ай бұрын
Aaaand this is why a well-defined static language like Rust is going to replace C++ eventually. I've been programming in C++ for a long time, and still do for work, but I find myself using Rust for everything I possibly can because of stuff like this. Why should I need to study a language's implicit (hidden) rules just to understand when something will be optimized or not? Why is UB so unacceptably trivial to achieve in C++? I stay up-to-date with C++ because the industry demands it, but the language is getting so bloated and arcane, I don't see younger developers ever wanting to get into this, and I don't blame them. Jason even said it himself that `constexpr` isn't even going to actually require the thing to be a constant expression in the upcoming C++26 standard... Good thing we have `consteval`... Just another nuanced thing my team / newcomers to the language are not going to understand or utilize. And this isn't even to mention the "Principal " engineers that still don't trust using smart pointers...
@germanassasin1046
@germanassasin1046 4 ай бұрын
constexpr was never required to be evaluated at compile time only, it was always meant to be double agent for both runtime and compile time. You can enforce evaluation of something that is constexpr, but unlike consteval which completely disappears after compilation, you can still call your constexpr function. Also no languange in existence will strip programmer from responsibility to think. Rust also has hidden rules that can incapacitate the perfomance like absence of inplace construction, it is just inevitable when you shoot for top perfomance. And instead of instantly doomsaying the very moment you see "trick c++ quiz", wait a moment and think about the most perfomant options in there. They are the simplest ones, that's why the talk is called "great c++ is_trivial"
@aniketbisht2823
@aniketbisht2823 4 ай бұрын
What Jason said about constexpr is that in C++26 you don't have to worry about making your code "constexpr friendly" because almost everything is able to be executed at compile time. Even and the upcoming SIMD library is constexpr capable. And that's a good thing. Meanwhile speaking of Rust : "Enjoy your ugly proc macros!".
@Spartan322
@Spartan322 4 ай бұрын
Rust doesn't fix these problems, those are superficial issues, the problem is that language designers don't consider legacy and when it becomes a problem its already too late, I already see that with Rust and it'll only get worse, C used to be young and simple and was considered easy to optimize but then systems became more complex and C kept needing to adopt new features, and now to use it properly is difficult, C++ came along to try and fix these issues and then it grew legacy on top of C legacy (which it used to overtake C) and now its a mess. Rust does not have a solution to this. Also the borrow checker isn't simple, any amount of complexity you add to the base function of a program (no matter where it happens) is inherently going to cause complexity issues in the program itself. There's other problems with Rust, like unstable ABI libraries, which make it pretty difficult to adopt as a replacement to C++ and the lack of direct support of C++ legacy which is how most big name derivative languages win marketshare.
@fullaccess2645
@fullaccess2645 3 ай бұрын
For the record, I'm studying a cs adjacent career and C++ is the language that interests me the most. I'd rather end up programming in C++ than in any web technology.
C++ Code Smells - Jason Turner - CppCon 2019
58:35
CppCon
Рет қаралды 78 М.
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 71 МЛН
Magic trick 🪄😁
00:13
Andrey Grechka
Рет қаралды 41 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 12 МЛН
CppCon 2019: Jason Turner “The Best Parts of C++"
58:36
CppCon
Рет қаралды 90 М.