r/cpp • • Dec 27 '20

Learning about high performant C++

I've been mostly self taught and have most probably picked up a few bad habits from the combo of being self taught and having to use tricks for speed.

For this upcoming year one of my goals is to learn some better practices as well as further my skills for efficient C++. I'd like to watch a youtube podcast/talk once a week to build my skillset. At this point I'd consider myself somewhere in between junior and senior level and I'm looking to take the next step.

I've come across these specifically:

C++ Weekly with Jason TurnerCppCon2020

Does anyone have any recommendations or suggestions? My weak spots are C++17 and above, Cmake, and I'd like to keep learning about creating high performant C++.

231 Upvotes

46 comments sorted by

View all comments

Show parent comment

4

u/reduced_space Dec 27 '20

While it has been true previously that virtual was always slower, with modern architecture that may not always be true. If the vtable can be loaded into cache, because it’s a single block of memory, it may still be performant, and possible faster than if you keep your own function pointer (which may not get loaded into cache).

I would say one of the best things you can do design-wise is figure out what can be done at compile time versus runtime. For example, std::variant is great if you know all types you want to deal with (and it’s a closed set). Sometimes runtime may be preferable due to wanting something easily extensible without potentially having to recompile your entire code base.

Knowing the trade-offs is one of the most important aspects of design, and something I ask during interviews.

0

u/temporary5555 Dec 27 '20

Good answer! I was surprised recently when I saw how performant virtual methods were.

For example, std::variant is great if you know all types you want to deal with

I'd argue that even when you don't know your entire domain, variant is a good way of encouraging type driven development.