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

Поділитися
Вставка
  • Опубліковано 28 лип 2024
  • 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 UA-cam 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
    UA-cam: JBGraphics
    ---
    Videos Streamed & Edited by Digital Medium: online.digital-medium.co.uk
    #cppcon #programming #cpp
  • Наука та технологія

КОМЕНТАРІ • 106

  • @bernhardmanfredgruber7156
    @bernhardmanfredgruber7156 Рік тому +76

    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 Рік тому +179

    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 Рік тому +3

      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 Рік тому +2

      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 Рік тому +3

      @@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 Рік тому +2

      Excellent talk, enjoyed it.

  • @SqueakyNeb
    @SqueakyNeb Рік тому +61

    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 Рік тому +7

      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 Рік тому +42

    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 Рік тому +18

    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 Рік тому +1

      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 4 місяці тому

      ​@@vcoolwhat would you advise such talent to not get used up and burned up by private company? Create your own?

    • @MantasXVIII
      @MantasXVIII 27 днів тому

      ​@@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 Рік тому +21

    This is a really well-organized and comprehensive presentation. Kudos and thank you!

  • @NongBenz
    @NongBenz Рік тому +12

    I'm only halfway through but the flowchart at 30:00 on passing parameters is golden

  • @whisper154
    @whisper154 Рік тому +22

    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 Рік тому +13

      I'll keep that in mind when working on version 2.0 for CppCon23

  • @BalanNarcis
    @BalanNarcis Рік тому +8

    Great talk Jan Bielak! 🤝

  • @victorshcherbakov4602
    @victorshcherbakov4602 Рік тому +5

    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.

  • @bunpasi
    @bunpasi Рік тому +4

    That's a lot of info in a short amount of time, while still being easy to grasp. Great talk!

  • @MaitreBart
    @MaitreBart Рік тому +12

    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.

  • @MichaelSchulzDaFritzmark
    @MichaelSchulzDaFritzmark Рік тому +2

    Great Talk! Looking forward to the next talks of you.

  • @learningcode314
    @learningcode314 Рік тому +3

    High quality presentation. Thanks Jan!

  • @_RMSG_
    @_RMSG_ Рік тому +3

    This is one of the best presentations out here for C++

  • @nmmm2000
    @nmmm2000 Рік тому +3

    Best performance talk I watched for 2022 :)

  • @manucanedo8039
    @manucanedo8039 Рік тому +6

    This is brilliant. Thank you.

  • @kartikmahajan4405
    @kartikmahajan4405 Рік тому +1

    commendable job, very well done. thanks a lot for keeping it precise and succinct.

  • @Hamid1Reza
    @Hamid1Reza Рік тому +1

    Very informative and compact! Thank you for all the ideas.

  • @exacoustics
    @exacoustics Рік тому +3

    Killer talk. Very helpful. Will likely rewatch several times

  • @acestapp1884
    @acestapp1884 Рік тому +9

    Thanks, very informative and easy to apply. I need a poster of slide 23 :)

  • @MrFalcon517
    @MrFalcon517 Рік тому +2

    Great presentation, I like the visualization and the order of subjects.

  • @videojeroki
    @videojeroki Рік тому +2

    I'm going to look for more content from Jan!
    Great presentation!!!!

    • @janbielak
      @janbielak Рік тому +3

      Thanks! You can check the links shown on the first slide of the talk. UA-cam’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.

  • @cppdev2729
    @cppdev2729 Рік тому +1

    Very nice presentation. The dude is in high school and already nailing it with c++

  • @martinlicht7132
    @martinlicht7132 6 місяців тому

    Very informative and comprehensive presentation of the topic!

  • @Moriadin
    @Moriadin Рік тому +1

    A great and most useful talk! Thank you!

  • @RadimPolasek
    @RadimPolasek Рік тому +4

    nice summary, thanks

  • @spaxio
    @spaxio Рік тому +2

    Great talk!

  • @chrisa8674
    @chrisa8674 Рік тому +1

    Excellent talk and advices

  • @younghsiang2509
    @younghsiang2509 Рік тому +5

    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?

  • @97Pedrito
    @97Pedrito Рік тому +4

    This is very impressive

  • @nicksklenicka8926
    @nicksklenicka8926 Рік тому +1

    This is very interesting!!!

  • @fondueeundof3351
    @fondueeundof3351 9 місяців тому

    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.

  • @khatdubell
    @khatdubell Рік тому +3

    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 Рік тому +1

      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.

  • @ThiagoBarbanti
    @ThiagoBarbanti Рік тому +2

    Great!

  • @treyquattro
    @treyquattro Рік тому +6

    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 Рік тому +3

      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.

  • @GeofftheMedio
    @GeofftheMedio Рік тому +9

    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 Рік тому +9

      That's correct, I forgot to mention inline namespaces as an alternative to static.

  • @cmdrwhiskeygalore3044
    @cmdrwhiskeygalore3044 Рік тому +1

    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.

  • @user-gc4ct3ci3e
    @user-gc4ct3ci3e 8 місяців тому

    nice talk!

  • @z140140
    @z140140 Рік тому +1

    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.

  • @minma02262
    @minma02262 12 днів тому

    Wow. Great talk 🎉 where is part 2

  • @dagoberttrump9290
    @dagoberttrump9290 Рік тому

    C++23 explicit object parameter declaration -- back to the roots. I hope we can get rid of objects altogether in the future.

  • @ethanwasme4307
    @ethanwasme4307 9 місяців тому

    would be great to see something in similar vein to graphics programming 👍

  • @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.

  • @kuddai92
    @kuddai92 Рік тому +2

    where can I find slides? As of 18 January of 2023 the repo in the description doesn't contain it.

    • @janbielak
      @janbielak Рік тому +1

      Hi, the slides are made in Slides (editor). I cannot post the link because UA-cam doesn’t like that, you should be able to find it by searching for the name of the talk.

  • @perfumedsea
    @perfumedsea Рік тому +2

    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 :)

  • @yangwei6761
    @yangwei6761 Рік тому +1

    coooooooooooool

  • @MindGameArcade
    @MindGameArcade Рік тому +3

    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 Рік тому +6

      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.

  • @graphicsRat
    @graphicsRat Рік тому +3

    Can you please post a link to the vectorizer utility. Thanks.

    • @janbielak
      @janbielak Рік тому +2

      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. UA-cam's moderation policies about links can be annoying. You can post the links in the summary. That way UA-cam knows you are not a rando posting links to exploit websites of something.

  • @phenixwutao
    @phenixwutao Рік тому +1

    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 UA-cam doesn’t like that, you should be able to find it by searching for the name of the talk.

  • @loogabarooga2812
    @loogabarooga2812 7 місяців тому

    That flowchart for function call sites imo should be memorized by every cpp programmer.

  • @unperrier5998
    @unperrier5998 8 місяців тому +1

    He seems so young to have such experience.

  • @videojeroki
    @videojeroki Рік тому

    slide 23 is the sad daily dilemma of c++ programmers :(

  • @alpers.2123
    @alpers.2123 Рік тому +30

    Im gettin old

  • @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 Рік тому +1

    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 Рік тому +10

      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 Рік тому +3

    presentation is way too goofy. Couldn't make it past the 5 minute mark.

    • @davecaloway1993
      @davecaloway1993 Рік тому +2

      Sounds like you're just salty because a high schooler knows more than you. Where's your CppCon talk bud?

    • @SqueakyNeb
      @SqueakyNeb Рік тому +19

      What's "goofy" about it?

    • @rocknroooollllll
      @rocknroooollllll Рік тому +3

      @@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 Рік тому +3

      I think that's a you problem. Content was great and very to the point.

    • @graphicsRat
      @graphicsRat Рік тому +5

      @@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!!!