CppCon 2016: Jason Turner “Practical Performance Practices"

  Рет қаралды 130,120

CppCon

CppCon

Күн бұрын

Пікірлер: 76
@seancpp
@seancpp 2 жыл бұрын
Jason Turner, Herb Sutter, Scott Meyers, Venkat Subramaniam, Kate Gregory, and Dylan Beattie I think are some of the greatest technical speakers of our day. I thoroughly enjoy every talk I've seen by each of those people
@pankajthapa1417
@pankajthapa1417 2 жыл бұрын
Arther o'dwyer, mayer scott, Klaus Iksagberg, Dimitri Nesteruk,
@virtualspecies
@virtualspecies Жыл бұрын
Jason's awesome - after watching his constexpr CppCon talk I'm now going through all his presentations; totally dig his style & you're certain to take away a couple of things from *every* talk 👍
@xealit
@xealit 4 ай бұрын
Arthur O'dwyer is pretty good
@wCupOfTea
@wCupOfTea 8 жыл бұрын
Jason Turner has one the best talks this year.
@SAFAR04
@SAFAR04 8 жыл бұрын
Yeah for sure. Hope he will do more next time.
@jostein6581
@jostein6581 8 жыл бұрын
Definitely agree on that.
@victornoagbodji
@victornoagbodji 8 жыл бұрын
yep
@EgD996
@EgD996 8 жыл бұрын
yes, and I also like your cppcast
@CharIie83
@CharIie83 6 жыл бұрын
I love how he is honest about his findings. Most people would try to forget and never mention again.
@seditt5146
@seditt5146 5 жыл бұрын
13:30 "Don't Const!" .... I like the way he thinks, ima do more of that ;)
@blackmav5
@blackmav5 8 жыл бұрын
Thank you Jason Turner for your talks. Compared to the time I spent watching it and what I get out of it, even if it just a repetition, really great! One of the best even.
@PatrickKellyLoneCoder
@PatrickKellyLoneCoder 5 жыл бұрын
Here's a tip for programming language snippets inside of presentations: Write out the code instead of taking a screen shot. Color that code as an editor would. Sometimes you'll need to remove the slide title; that's fine, the point is the code example. The title can be put on a title slide then move over to the code slide.
@n3whous3
@n3whous3 8 жыл бұрын
the c++17 c64 was an awesome talk, and this too
@moonhowler667
@moonhowler667 Ай бұрын
Already love the first example. I wrote a performance/frame timer func, and obviously that *needs* to be as performant as possible so as not to burden the rest of... well, everything. Initially, I used Chrono. Too slow. Then I switched to filetime, which was much faster. But it still soaked up like 5% of my spent CPU, so, why? Well I checked out the ASM and saw that for some reason it was performing two [load effective], [copy]'s. I then realized, it's because I'm using both halves of the ULI I made to extract the full accuracy quadpart. I checked and, the low part works fine for comparisons for up to around 450s. A frame is 16.667ms or below. I dropped the upper part of the ULI along with the quadpart line, and the function was 50% faster. Don't trust the gut, trust the ASM and benchmarking.
@alexeyfadieiev4070
@alexeyfadieiev4070 Жыл бұрын
I didn't get on 40:00 , why many instantiations of shared pointers influence on compile RAM and time, but unique_ptr does not? Could someone please explain this point? Thank you.
@MrBufellow
@MrBufellow 9 ай бұрын
I believe unique pointers just manage the scope of the pointer and don't let you move it outside the scope. They delete themselves upon the scope ending. With shared pointers, the references have to be kept track of and incremented and decremented every time you move it around.
@mikevasiljevs412
@mikevasiljevs412 8 жыл бұрын
@13:30 "don't _const_"?
@lextorn92
@lextorn92 4 жыл бұрын
11:22 if you spawn more threads on val of uncached Int, you can be calculating more than once, if context switch will occur after entering if and before setting is_calculated.
@berlin-unlocked
@berlin-unlocked 3 жыл бұрын
of course, it must be done with mutex. exactly the same as in Singleton pattern
@bemo6434
@bemo6434 9 ай бұрын
What I learned from this talk: don't use red syntax highlighting on a gray background!
@musicalfringe
@musicalfringe 5 жыл бұрын
This reminded me of a few habits I ingrained so long ago that I don't even notice them any more.
@dimaredko2091
@dimaredko2091 7 жыл бұрын
@7:50 Jason showed string with const modifier and stated that "const" may increase performance. I didn't get that? I thought that during assignment construction only corresponding constructor will be called, isn't it? and if so how const is helpful here
@TrueWodzu
@TrueWodzu 6 жыл бұрын
You are right, const is not helpful at all in this example. But maybe the example is too small and compiler sees that string without const is not modified anyway so it is const qualified internally anyway.
@masheroz
@masheroz Жыл бұрын
If the compiler knows that a variable is never going to be changed, it can do other optimisations in other circumstances
@korcanucar5395
@korcanucar5395 6 жыл бұрын
Practical Performance Practices - may be you need to apply some principles to the title of the presentation, as well :) great talk !
@IndellableHatesHandles
@IndellableHatesHandles Жыл бұрын
Storing a shared_ptr in a class so that you can have a getter for a complicated data structure is the only time I ever use shared_ptr.
@yyyy-uv3po
@yyyy-uv3po Жыл бұрын
I thought that lambda were implemented by std::function and binding under the hood, how come they don't lead to any overhead ? I mainly use lambda for storing callbacks
@ХузинТимур
@ХузинТимур Жыл бұрын
Nope. It is most often implemented as new anonymous class with overriden call operator. So each lambda has unique type.
@TV20
@TV20 Жыл бұрын
26:26 why function accepting Base by reference as passed it to pointer?
@masheroz
@masheroz Жыл бұрын
He explained that was a bug.
@mrlithium69
@mrlithium69 7 жыл бұрын
That stuff about Base/Derived class redefining the virtual destructor disables move operations. and the solution to type all those default rules out.. ugh i cant believe that is the solution
@NXTangl
@NXTangl 5 жыл бұрын
C++ is actually surprisingly bad at being a fast language.
@AxelStrem
@AxelStrem 7 жыл бұрын
great talk, but I still don't see how move/copy semantics can be useful in polymorphic classes. Like, if you want to move the polymorphic object, you pretty much just reassign the pointer; and for copies you'd need a virtual clone method. As the person @17:30 (is trying to) say, enabling copy/move just allows you to implicitly slice objects, hardly a good practice
@dresnyd
@dresnyd 8 жыл бұрын
20:26 If the string 's' was const then how would you move it.
@noamrodrik3776
@noamrodrik3776 7 жыл бұрын
You can move it, because it is being copied to the struct S via the constructor's parameter, which is copied by value.
@Henrik0x7F
@Henrik0x7F 6 жыл бұрын
Peterolen it's first copied and then moved from the copy
@oleghab2
@oleghab2 4 жыл бұрын
The fact is you actually can make two constructors to ensure copy elision struct A { std::string a; A(std::string const& a_) : a(a_) {} A(std::string && a_) : a(std::move(a_)) {} };
@n3whous3
@n3whous3 8 жыл бұрын
just one comment for 11:30 - even the values became atomic, de method should be atomic itself. The variable usages could get inconsistent because you didn't block the whole function. If you know what I mean
@Tau-qr7f
@Tau-qr7f 2 жыл бұрын
this talk is super helpful for me
@CppCon
@CppCon 2 жыл бұрын
Very pleased to hear that the presentation was helpful!
@robingreen7920
@robingreen7920 2 жыл бұрын
thanks
@MrZapper1960
@MrZapper1960 3 жыл бұрын
Wow this one took off at 3:00
@billw2461
@billw2461 8 жыл бұрын
Regarding unique_ptr vs shared_ptr (kzbin.info/www/bejne/q6upZahvgMyIjas): I do not get comparable results in MSVC. shared_ptr ends up (slightly) faster to compile (with default compiler settings under debug). EXE is still bigger though, and I'm sure the performance implications still apply.
@thePrzemko17
@thePrzemko17 7 жыл бұрын
40:00 anyone can explain me why there will be only one shared_ptr created? I tought the vector is constructed of shared pointers, and there are 4 objects.
@TrueWodzu
@TrueWodzu 6 жыл бұрын
The question was about number of instantiations of template. Since we use only one type which is int, only one instance of template will be created.
@AxelStrem
@AxelStrem 7 жыл бұрын
I thought std::make_shared is intrusive (1 allocation for both control block and the object)
@dawikur
@dawikur 8 жыл бұрын
at 12:34 there is still data race
@varunnagp3903
@varunnagp3903 8 жыл бұрын
Yes, atomics dont quite solve race condition
@vonkruel
@vonkruel 8 жыл бұрын
I don't see it.
@vonkruel
@vonkruel 8 жыл бұрын
I usually think of a data race as a bug. In this case I'd say there's no problem with the code. Whatever we do to prevent the value being calculated multiple times is probably going to hurt performance.
@dawikur
@dawikur 8 жыл бұрын
You are right, but at this point it might we worth mentioning that using multiple atomic's can still be dangerous.
@fob3476
@fob3476 2 жыл бұрын
I think there's a race condition (atoi() can be called multiple times), but no data race (no undefined behavior)
@michaeldunlavey6015
@michaeldunlavey6015 2 жыл бұрын
All these talks are fine, but I'm always struck by what's missing. What's missing is _diagnosis._ _How do you know what to fix?_ There's a bone-simple method I've used for half a century, and it resembles the _poor man's profiler._ I don't do it for economic reasons. I do it because _it actually works,_ where profilers don't. I'm not saying profilers don't measure stuff. I'm saying _they don't tell you much to fix,_ and if you're a typical programmer, you're happy to hear that. All it requires is the ability to take a SMALL NUMBER of samples of the call stack, such as with a debugger. AHEM. That's CALL STACK, where you can see each line, not just PROGRAM COUNTER, which is all the optimizer cares about. Look for calls you could avoid. You're looking for code that could be improved, which is kind of like a bug, but not a correctness bug. After you fix it, you realize it was a bug, but only in the sense that it was doing unnecessary stuff - a speed bug. If a speed bug is big enough to be worth fixing, i.e. if the time that could be saved by fixing it, is more than 10% (typically it is 20%-90%), then you WILL SEE IT two or more times in a small number of samples. I usually take between 5 and 20 samples. If you see it just once, that could be by chance. But if you see it twice, you can be sure it's real. And, there is never just one speed bug. Usually there are several, in a range of sizes. Here's the thing: _removing one magnifies the others, so it takes fewer samples to see them._ The minimum execution time you can get to is what's left over after they've all been removed, and that can be _orders of magnitude_ smaller than what you started with. Just a few typical speed bugs are: - Calling *new* or *delete* when a prior object could just be re-used. - Calling *pushback* which deletes, reallocates, and copies an array just to make it 1 element bigger. - I/O time formatting or writing lines to a log file that nobody reads. - I/O time reading a DLL file to get a string translation resource, when the string doesn't need to be translated. - Calling an array-indexing function to index an array, to make sure the index is within range, when you know the index cannot be out of range. - Calling *==* between strings to check program state, when integers could be used. ... there is no limit to the ways time can be wasted.
@MrAbrazildo
@MrAbrazildo 8 жыл бұрын
- 9:00, wouldn't it be better coded as: const std::string s (std::move (std::string ("long string is mod ") + ('0' + std::rand() % 4))); ? - 13:25, couldn't you had inline val() and the constructor? - 25:40, is that valid for explicit casts of dynamic_cast too?
@ХузинТимур
@ХузинТимур Жыл бұрын
There is no point of moving temporary because it is already rvalue. On contrary, using std::move can prevent copy elision and be slower.
@lincolnsand5127
@lincolnsand5127 4 жыл бұрын
He should do `std::stoi` instead of `std::atoi(string.c_string())`
@MuqsitNawaz
@MuqsitNawaz 4 жыл бұрын
I'd rather prefer std::from_chars (since C++17).
@vivekatbitm
@vivekatbitm 5 жыл бұрын
Doesn't IIFE has cost and should it be used just for const initialisation as const is just for code maintainability n has no performance gains?
@Swedishnbkongu
@Swedishnbkongu 3 жыл бұрын
At even O1 optimizations it should be inlined
@vertigo6982
@vertigo6982 5 жыл бұрын
24:20 incrementing REFERENCE count by passing by VALUE? Not passing by REFERENCE?
@kebien6020
@kebien6020 5 жыл бұрын
yes shared_ptr keeps a refcount which is just a number that is incremented atomically every time a new shared_ptr is created from copying another one and decremented when a shared_ptr is destructed. When the refcount reaches 0 the object owned by the pointer(s) is destroyed. When you pass the shared_ptr by value you are copying it so it increments the refcount, if you instead pass the shared_ptr by reference you are essentially passing a pointer to the shared_ptr object and that does not count as copying the shared_ptr. Passing a shared_ptr by value means sharing the ownership of the underlying object, passing it by reference does not entail sharing and its usually an error. As shown in the slides you most likely just want to .get() the raw pointer and pass it.
@EnriqueSalceda-k4v
@EnriqueSalceda-k4v 23 күн бұрын
Tbh that 'interaction' thing makes this way longer than needed. Also comes across as a bit pedantic.
@sabetaytoros4123
@sabetaytoros4123 7 жыл бұрын
10::34 Don"t do more than you have to class (Int) { Int(std::string t_s) : s(t_s) , value(std::atoi(s)) {}; std::string s; int value; } ; If you calculate the value in the constructor you dont"t have to declare is the variable isCalculated; And you dont need to call the Val function. So the function Val is obselete.
@sabetaytoros4123
@sabetaytoros4123 7 жыл бұрын
Opps I apoligize. You have already done it.
@ashrasmun1
@ashrasmun1 7 жыл бұрын
I'm a bit puzzled, because at lacture about "Practical Performance Practices" people call out bugs on so many slides...
@TrueWodzu
@TrueWodzu 6 жыл бұрын
"So many slides" is actualy a whopping amount of two and it does not influence in anyway the message they are conveying.
@Elbrasch
@Elbrasch 8 жыл бұрын
at 28:50 using ' ' instead of std::endl, that makes my code linux locked, because windows uses ' '. Not something that will cause me problems most of the times, but something that should be mentioned anyways, because portability should be something one should keep in mind.,
@hkmix
@hkmix 8 жыл бұрын
' ' is portable on the commandline, AFAIK. When you're just printing to stdout, ' ' will always give you what you expect. You'll only have a problem with Notepad, but you can also open the stream in text mode in that case, which does platform-specific conversions.
@kaboissonneault
@kaboissonneault 8 жыл бұрын
Jason Turner mentioned this in one of his C++ weekly videos on youtube. ' ' is portable
@MrAbrazildo
@MrAbrazildo 8 жыл бұрын
Nope. Windows uses ' ' (LF); and Linux, " " (CRLF). I saw that a bunch of times, using hex editor. If your app. expected to find ' ', it may crash if it was important.
@hkmix
@hkmix 8 жыл бұрын
You actually have those flipped (Windows uses CRLF, modern *NIX uses LF). Unless you're in a file, std::cout
@bloopbleep7082
@bloopbleep7082 4 жыл бұрын
iostreams are formatted IO. That means they do newline conversions, and possibly other conversions. Also on Windows the newline sequence is .
@programmingeverything
@programmingeverything 7 жыл бұрын
So many bugs on your slide
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 23 МЛН
Mia Boyka х Карен Акопян | ЧТО БЫЛО ДАЛЬШЕ?
1:21:14
Что было дальше?
Рет қаралды 12 МЛН
Which team will win? Team Joy or Team Gumball?! 🤔
00:29
BigSchool
Рет қаралды 15 МЛН
CppCon 2017: Chandler Carruth “Going Nowhere Faster”
1:00:58
C++ Code Smells - Jason Turner
56:11
NDC Conferences
Рет қаралды 77 М.
Better Code: Runtime Polymorphism - Sean Parent
57:33
NDC Conferences
Рет қаралды 72 М.
CppCon 2019: Jason Turner “The Best Parts of C++"
58:36
CppCon
Рет қаралды 91 М.
C++17 - The Best Features - Nicolai Josuttis [ACCU 2018]
20:26
ACCU Conference
Рет қаралды 40 М.
Back to Basics: C++ API Design - Jason Turner - CppCon 2022
1:00:42
Is C++ better than C?
1:46:10
Tsoding Daily
Рет қаралды 50 М.
Motorbike Smashes Into Porsche! 😱
00:15
Caters Clips
Рет қаралды 23 МЛН