The Most Important Optimizations to Apply in Your C++ Programs - Jan Bielak - CppCon 2022

  Рет қаралды 54,360

CppCon

CppCon

Күн бұрын

cppcon.org/
---
The Most Important Optimizations to Apply in Your C++ Programs - Jan Bielak - CppCon 2022
github.com/CppCon/CppCon2022
Writing efficient programs is hard. This is because it requires a lot of knowledge, experience and strategic thinking. There have been many talks on optimization and often each addresses a single concept. Being able to achieve a bird’s eye view of factors affecting performance often requires many hours of researching the topic. To lessen the mental burden of optimizing programs, I have picked out the techniques, I believe are most important. During the talk, I will present them in an organized manner and provide practical examples of how they can be applied.
I will first discuss what I believe are the main goals efficient programs strive to achieve. Then, I will present the general methods of achieving those goals. Then, for the majority of the talk, we will discuss a few dozen performance opportunities. For each of them, I will explain the underlying mechanism of how the optimisation works. I will avoid bluntly giving guidelines to follow without explanation. Each of the techniques naturally comes with its costs, and those will be discussed as well.
I will additionally discuss various performance pitfalls. These are sometimes called “premature pessimisations” in contrast to the often used term of “premature optimizations”. I will show examples of optimizations which do not incur any cost on program readability or maintainability and as such should be considered performance best practices. Avoiding their use doesn’t improve code in any manner, while making it slower.
This talk is intended for a diverse audience, as after all, probably most of the C++ community is interested in performance. It is appropriate for hobbyists and professionals alike, with varying experience with the language, due to the gradual increase in difficulty of examples. It will be a time productively spent.
---
Jan Bielak
Jan Bielak is a student at the Warsaw Staszic High School. His main areas of interest are physics and computer science. He is especially into advanced C++ programming and physically based real-time rendering. He also hosts an educational KZfaq channel. He is involved in the CyberDuck project and in the PaSh project. In free time, he likes to create renders in Blender.
Website: janbielak.com
GitHub: janekb04
KZfaq: JBGraphics
---
Videos Streamed & Edited by Digital Medium: online.digital-medium.co.uk
#cppcon #programming #cpp

Пікірлер: 105
@bernhardmanfredgruber7156
@bernhardmanfredgruber7156 Жыл бұрын
This talk was one of the most comprehensive, complete and approachable overviews of performance considerations in C++ I have ever seen. Just amazing!
@janbielak
@janbielak Жыл бұрын
Thanks for watching! If you have any questions, feel free to leave them here in the comments and I will respond to them. Update: I'll be hosting part 2 at CppCon 2023 in October.
@Fureeish
@Fureeish Жыл бұрын
Hey, great talk. Would it be possible to share the presentation's source code? I have a feeling that it was made using reveal.js and I am interested in the details of how you managed to construct some of the slides. However, if this it not reveal.js or you do not wish to share the source of your presentation, just let me know - it's totally fine :)
@treyquattro
@treyquattro Жыл бұрын
I too was impressed by some of the slide animations - a step above PowerPoint, unless PP has stepped up its game recently (well, since the last time I used it - "some time ago")
@superscatboy
@superscatboy Жыл бұрын
Great talk! Thanks 👍
@janbielak
@janbielak Жыл бұрын
@@treyquattro It did step up, but not enough for me. I originally tried using PowerPoint, but it wasn't flexible enough. One of the goals of my talk was to have visually attractive slides which convey information through animation because of the large information density.
@higgins007
@higgins007 Жыл бұрын
Excellent talk, enjoyed it.
@SqueakyNeb
@SqueakyNeb Жыл бұрын
I'm only part way through this (and will be back to finish it) but I've gotta say: it's SO nice to have one of these remote talks given by someone that has a good microphone and some enthusiasm for their content. Some of them are so hard to listen to.
@bunpasi
@bunpasi Жыл бұрын
True. As someone to whom English is not the first language, I can manage an accent or a bad microphone ... but not both.
@aurelien221
@aurelien221 Жыл бұрын
It's amazing that you managed to cover all these topics in just one hour. It gave me a lot of ideas. Thanks!
@ennio5763
@ennio5763 Жыл бұрын
The author looks like a little kid, and already knows the in and outs of performance programming across multiple levels. This is a great talk, honestly. You should use it as a great resume intro, that will land you a well-paid job in a great company.
@vcool
@vcool Жыл бұрын
Unfortunately, this kind of talent will likely get quickly used up and burned by private equity. It is what happens to most such talent. P.E. is the economic monster, a result of fake/Keynesian economics, and it wrecks everything.
@malborboss
@malborboss 3 ай бұрын
​@@vcoolwhat would you advise such talent to not get used up and burned up by private company? Create your own?
@MantasXVIII
@MantasXVIII 10 күн бұрын
​@@vcoolSir, this is a Wendy's. If someone is not able to fulfill their own potential, it's not anyone else's fault but theirs. Obviously except in extreme circumstances but he lives in the Western world so that does not apply.
@christopherhayden8442
@christopherhayden8442 Жыл бұрын
This is a really well-organized and comprehensive presentation. Kudos and thank you!
@NongBenz
@NongBenz Жыл бұрын
I'm only halfway through but the flowchart at 30:00 on passing parameters is golden
@MaitreBart
@MaitreBart Жыл бұрын
Nice and quite complete work you could fit inside such a limited duration. Lot of concrete pointers where to start investigating things that could be optimized in c++ code. I have many years of experience in c++ and I'm almost jealous by all the knowledge you're able to share at your young age! The most important is that you seem to have experimented what you're talking about. I'll definitely keep a tag on this video for future reference. One of the best content on a highly debatable subject, in the past years.
@whisper154
@whisper154 Жыл бұрын
Very good talk! A lot of pointers here that I preach in my day to day. You cover a lot of ground and go into just the right amount of detail. One thing worth adding for future talks is how virtual tables affect performance. I still see a lot of engineers who are taught the old school OOP paradigm and there is some contention between those that think virtual calls are absolutely evil and those that think they are a necessary evil.
@janbielak
@janbielak Жыл бұрын
I'll keep that in mind when working on version 2.0 for CppCon23
@bunpasi
@bunpasi Жыл бұрын
That's a lot of info in a short amount of time, while still being easy to grasp. Great talk!
@nmmm2000
@nmmm2000 Жыл бұрын
Best performance talk I watched for 2022 :)
@victorshcherbakov4602
@victorshcherbakov4602 Жыл бұрын
This talk is a good aggregation of different optimizations. It can be used as a hint or a spreadsheet with optimizations just to recall them sometimes. Thanks.
@_RMSG_
@_RMSG_ Жыл бұрын
This is one of the best presentations out here for C++
@learningcode314
@learningcode314 Жыл бұрын
High quality presentation. Thanks Jan!
@BalanNarcis
@BalanNarcis Жыл бұрын
Great talk Jan Bielak! 🤝
@MichaelSchulzDaFritzmark
@MichaelSchulzDaFritzmark Жыл бұрын
Great Talk! Looking forward to the next talks of you.
@manucanedo8039
@manucanedo8039 Жыл бұрын
This is brilliant. Thank you.
@exacoustics
@exacoustics Жыл бұрын
Killer talk. Very helpful. Will likely rewatch several times
@kartikmahajan4405
@kartikmahajan4405 11 ай бұрын
commendable job, very well done. thanks a lot for keeping it precise and succinct.
@Hamid1Reza
@Hamid1Reza Жыл бұрын
Very informative and compact! Thank you for all the ideas.
@acestapp1884
@acestapp1884 Жыл бұрын
Thanks, very informative and easy to apply. I need a poster of slide 23 :)
@cppdev2729
@cppdev2729 Жыл бұрын
Very nice presentation. The dude is in high school and already nailing it with c++
@MrFalcon517
@MrFalcon517 Жыл бұрын
Great presentation, I like the visualization and the order of subjects.
@Moriadin
@Moriadin Жыл бұрын
A great and most useful talk! Thank you!
@janbielak
@janbielak Жыл бұрын
Thanks!
@videojeroki
@videojeroki Жыл бұрын
I'm going to look for more content from Jan! Great presentation!!!!
@janbielak
@janbielak Жыл бұрын
Thanks! You can check the links shown on the first slide of the talk. KZfaq’s autonomous comment moderation is very restrictive about promoting other motion picture broadcasters’ outlets registered on the service. Hence, to creatively work around the commenting system’s limitations, I will say that the author of the presentation has also done other C++ talks, the recordings of which are also available on the platform.
@martinlicht7132
@martinlicht7132 5 ай бұрын
Very informative and comprehensive presentation of the topic!
@RadimPolasek
@RadimPolasek Жыл бұрын
nice summary, thanks
@chrisa8674
@chrisa8674 11 ай бұрын
Excellent talk and advices
@spaxio
@spaxio Жыл бұрын
Great talk!
@97Pedrito
@97Pedrito Жыл бұрын
This is very impressive
@nicksklenicka8926
@nicksklenicka8926 Жыл бұрын
This is very interesting!!!
@cmdrwhiskeygalore3044
@cmdrwhiskeygalore3044 Жыл бұрын
Very necessary lecture. I don't think I took as much away from any other lecture as I have taken from this lecture. I always wanted to write my own malloc replacement but mimalloc does the job. Never knew it existed until this lecture (head buried in sand syndrome). As I only write real-time on Widows (Linux debugger not fit for real-time debugging, developed all my real-time for Linux on Solaris sparc then ported to Linux) I decided just to go with mimalloc. Still not sure if Linux debugger has been improved but I got burnt so badly by it I decided never again. As an old dog of a programmer I'm currently going through the forge of bringing myself up to date. C++20 is really nice but I have to admit I am looking forward to C++23 so will delay my development until C++23 is out and in the meantime will spend the time on re-educating myself. In my day colleges and universities used Cobol and Pascal. Not even sure those two exist now. Not sure why they did not settle on Fortran. Still don't know why ML does not favour Fortran but I am a C++ and Java programmer and refuse to move from those two as I am just too old. Note: Hate Java, but it pays the rent. I ported to iRMX too using Intel C/C++ compiler back in the day. Sometimes to get the best performance you need to develop in the Kernel. I did that to re-write the Microsoft NT serial driver as it was too inefficient.
@ThiagoBarbanti
@ThiagoBarbanti Жыл бұрын
Great!
@khatdubell
@khatdubell Жыл бұрын
35:50 I haven't dug into C++23 because i can't use it...but i love this. Been wanting something like this for awhile.
@janbielak
@janbielak Жыл бұрын
As far as I know, as of now, only MSVC 19.32 and up supports a subset of P0847. I am also looking forward to wide adoption of this language feature, especially for its applications in CRTP.
@younghsiang2509
@younghsiang2509 Жыл бұрын
The const bool part really helped! Normally, trying to put the if statement outside of the for loop is gonna make the code look bad. But a const bool solved it elegantly
@tbkih
@tbkih 11 ай бұрын
can you say where exactly is this part?
@fondueeundof3351
@fondueeundof3351 8 ай бұрын
Impressive preso you really know what you're talking about. What I would appreciate is an indication for the various C++ keywords that appear in the code snippets and elsewhere in which C++ version they were introduced.
@user-gc4ct3ci3e
@user-gc4ct3ci3e 7 ай бұрын
nice talk!
@dagoberttrump9290
@dagoberttrump9290 Жыл бұрын
C++23 explicit object parameter declaration -- back to the roots. I hope we can get rid of objects altogether in the future.
@treyquattro
@treyquattro Жыл бұрын
very good presentation. My only issue was that Jan seemed to imply that thrashing is the normal situation of bringing in page files from backing storage whereas it's a pathological scenario in which paging-in memory virtually immediately results in a successive eviction of another page and this situation cascades, leading to a scenario in which all the process's CPU cycles are spent handling page faults. This scenario rarely - if ever - happens in modern computing.
@janbielak
@janbielak Жыл бұрын
That wasn't my intention. "If page faults occur frequently [...] this is called thrashing " was meant to be a summary of how you describe thrashing. I didn't want to spend time going into the details, as it wasn't really relevant for the talk.
@kuddai92
@kuddai92 Жыл бұрын
where can I find slides? As of 18 January of 2023 the repo in the description doesn't contain it.
@janbielak
@janbielak Жыл бұрын
Hi, the slides are made in Slides (editor). I cannot post the link because KZfaq doesn’t like that, you should be able to find it by searching for the name of the talk.
@z140140
@z140140 11 ай бұрын
21:19 since CPU will anyway predict the branch, the effect of [[likely]] is very small. I've seen it mainly in the better register allocation especially for x86-32 code (having only 6-7 registers at hand)
@janbielak
@janbielak 10 ай бұрын
In this case, yes. This was only meant to be a minimal example. However, it is important to remember that the BTB (Branch Target Buffer) has a limited capacity. If this function is called rarely, then it doesn't matter that the branch wouldn't be cached in the BTB, as it's overhead would be low (because of the rarity). However, if there would be a lot of, theoretically, well predictable branches, being constantly executed (or at least more than the BTB can handle), then branch prediction performance would be suboptimal.
@AhmedSam
@AhmedSam 8 ай бұрын
It's impressive that this list more or less complete of actually what to do when you plan performance optimizations. Well presented and concise with examples. Probably the only wish was to elaborate more on the branch predictions. But bloody good efforts.
@ethanwasme4307
@ethanwasme4307 9 ай бұрын
would be great to see something in similar vein to graphics programming 👍
@GeofftheMedio
@GeofftheMedio Жыл бұрын
For 17. Use static for internal linkage, why use static rather than an anonymous namespace? C++ Core Guidelines SF.22 suggests anonymous namespaces.
@janbielak
@janbielak Жыл бұрын
That's correct, I forgot to mention inline namespaces as an alternative to static.
@graphicsRat
@graphicsRat Жыл бұрын
Can you please post a link to the vectorizer utility. Thanks.
@janbielak
@janbielak Жыл бұрын
Hi, the commenting system’s automatic moderation policies prevent posting links in the comments or mentioning profiles on other social media platforms. You can check out the Vectoriser repository from an account to which a link is provided on the first slide of the talk.
@graphicsRat
@graphicsRat Жыл бұрын
@@janbielak Thanks. KZfaq's moderation policies about links can be annoying. You can post the links in the summary. That way KZfaq knows you are not a rando posting links to exploit websites of something.
@loogabarooga2812
@loogabarooga2812 6 ай бұрын
That flowchart for function call sites imo should be memorized by every cpp programmer.
@phenixwutao
@phenixwutao Жыл бұрын
where is the presentation, please? would like to keep it as a guidance.
@janbielak
@janbielak Жыл бұрын
Hi, the slides are made in Slides (editor). I cannot post the link because KZfaq doesn’t like that, you should be able to find it by searching for the name of the talk.
@yangwei6761
@yangwei6761 Жыл бұрын
coooooooooooool
@perfumedsea
@perfumedsea Жыл бұрын
Very helpful. Maybe someone has a wiki page to list all these helpful optimization gotchas?
@janbielak
@janbielak Жыл бұрын
The StackOverflow x86 tag wiki is a good place to start.
@perfumedsea
@perfumedsea Жыл бұрын
Thanks. Checked but not what I expected. I saw a list at the end of this video which kind of a good one. I shall print it :)
@unperrier5998
@unperrier5998 8 ай бұрын
He seems so young to have such experience.
@MindGameArcade
@MindGameArcade Жыл бұрын
Great summary, my only big problem is the title. The most important optimization by multiple orders of magnitude will always be algorithmic complexity. If your program is bubble sort, you can apply everything in this video and it will still be slower (on average) than a proper sorting algorithm.
@janbielak
@janbielak Жыл бұрын
Hi, I agree that algorithmic complexity has a significantly larger impact on performance than all of the presented techniques. I do mention that at the beginning of the talk. Regardless, the talk is about optimizations that apply to some given program. I assume that programs using different algorithms are different (potentially) unoptimized programs, in the sense of language and hardware efficiency - the main classes of techniques covered in the talk.
@alpers.2123
@alpers.2123 Жыл бұрын
Im gettin old
@videojeroki
@videojeroki Жыл бұрын
slide 23 is the sad daily dilemma of c++ programmers :(
@Boneamps
@Boneamps 9 ай бұрын
Nice Presentation. But by the end of the obvious side reading from a script became to monotone. Even if it takes longer to prepare it would be much nice to hear a normal person speaking in their natural mannerism other than just reciting the video's script
@thegod3500
@thegod3500 Жыл бұрын
string_view is almost always useless because it can't garantee zero ending for OS\C api usage
@UnrealEngine_Master
@UnrealEngine_Master Жыл бұрын
This should be renamed to "Optimization of C++ programs for dummies". It's just an overview of different techniques, often without examples what it gives.
@janbielak
@janbielak Жыл бұрын
The main purpose of the talk was to inform of optimization opportunities, rather than their applications. That’s because the domain of optimization is very large. If all optimization knowledge were a book, this talk would be (a part of) its table of contents. This is the talk I would’ve wished to see instead of having to look around the internet. There is plenty of information about each of these techniques, but I am yet to see an approachable review of many different ones.
@Dziaji
@Dziaji Жыл бұрын
presentation is way too goofy. Couldn't make it past the 5 minute mark.
@davecaloway1993
@davecaloway1993 Жыл бұрын
Sounds like you're just salty because a high schooler knows more than you. Where's your CppCon talk bud?
@SqueakyNeb
@SqueakyNeb Жыл бұрын
What's "goofy" about it?
@rocknroooollllll
@rocknroooollllll Жыл бұрын
@@SqueakyNeb It's not 'goofy' in any meaning of 'goofy'. Well done, Jan, a well thought out and well-presented talk! (Trolls will troll, please ignore their stupid comments)
@johnbarbero757
@johnbarbero757 Жыл бұрын
I think that's a you problem. Content was great and very to the point.
@graphicsRat
@graphicsRat Жыл бұрын
@@SqueakyNeb I think it was read, so there was no ad libbing but its okay. Also (**holy cow** )the speaker is a High school student!!!
Branchless Programming in C++ - Fedor Pikus - CppCon 2021
1:03:57
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 107 МЛН
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 67 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 67 МЛН
i wrote my own memory allocator in C to prove a point
5:23
Low Level Learning
Рет қаралды 354 М.
C++ Super Optimization: 1000X Faster
15:33
Dave's Garage
Рет қаралды 303 М.
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 89 М.
C++ cache locality and branch predictability
10:43
mCoding
Рет қаралды 79 М.
How I use C++: a line-by-line code review
1:40:40
strager
Рет қаралды 233 М.
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 813 М.
-memory-safe C++ - Jim Radigan - CppCon 2022
1:05:45
CppCon
Рет қаралды 21 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 36 МЛН
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 38 МЛН
Первый обзор Galaxy Z Fold 6
12:23
Rozetked
Рет қаралды 401 М.