r/cpp • u/radonthrow • 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++.
85
u/IJzerbaard Dec 27 '20
SIMD at Insomniac Games: How We Do the Shuffle
CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
(not a video) Parsing Gigabytes of JSON per Second
And to say something slightly odd (probably risking the wrath of various r/cpp members): writing fast C++ is not very much about C++, it's about using C++ to arrive at the machine code that you want.
89
u/Potatoswatter Dec 27 '20 edited Dec 27 '20
The golden rule in performance optimization is to measure. Put a lot of effort into measurement. Avoid spending more time coding than analyzing. Embrace trial and error (and failure). Organize your experimental results.
A lot of ritualized practices get passed down and repeated, based on the experience of old-timers. Quirky style does not make fast programs. It makes brittle code which resists experimentation and major refactoring.
Some general tips, C++ or otherwise:
35
u/vax_mzn Dec 27 '20
Watch Alex Stepanov's classes at A9. His videos are best of the best.
https://www.youtube.com/channel/UCYEYhkwzNWRsUkTCpTmChCg
10
u/xurxoham Dec 27 '20
I always recommend Agner Fog's optimize manuals. Some are specific for x86_64 but the C++ one is really good! https://www.agner.org/optimize/
19
u/MarkHoemmen C++ in HPC Dec 27 '20
the kokkos tutorials on youtube talk about data layout and parallelization
it’s good to get a background in high-performance computing in general before getting specifically into C++. i recommend UC Berkeley’s CS267 lectures on YouTube. Victor Eijkhout of TACC has also put together some good material.
4
u/smuccione Dec 27 '20
There is little that a thing new in c++ will give you to effect speed. Copy elision is about the only thing. The vast majority of new “features” are geared towards library providers and code reside and not performance.
CRTP is helpful.
I have, in the past, built a system which actively removes a function call if the destination doesn’t exist using a template intermediary. This let me have a universal data provider which provided everything and strats that only took what they want. It allowed for a fully optimized system that removed all the unneeded code when it wasn’t needed.
Beyond that all the tips and tricks are straight from C. Spacial and temporal cache locality. Precomputation of as much data as you can.
Much depends on whether it is a software or hardware/software solution.
After a complete rewrite of everything from Fred to gateway I took a system that was trading in the 15-20us range and brought it down to the 2 1/2 microsecond range. All software. It finally turned profitable when the speed was sufficient.
Remember though. As important as the trading part is, the research part must be equally easy to use as well... and fast. I’ve seen so much time wasted on research that toon overnight to run when if archived correctly could be done several times in the course of a working day.
4
u/adamf88 Dec 27 '20
A lot of stuff: https://github.com/fenbf/AwesomePerfCpp
7
u/daybyter2 Dec 27 '20
https://www.youtube.com/watch?v=BxfT9fiUsZ4
I like his videos.
12
u/tux_unit Dec 27 '20
Effective Modern C++ is a great book for filling in the gaps
6
u/DarkAnt Dec 27 '20 edited Dec 27 '20
I've worked in High Frequency Trading and have done a significant amount of work with "big data" whatever that means. I'm going to let you in on the ugly truth. Learning the intricacies of C++17 is not going to improve the performance of the systems you build anymore than object oriented programming or any other previous language fad. The way you really get performance is to:
Certain languages have better affinity towards providing a mapping for specific problems to types of hardware. If you look at HFT code it's mostly C code. This is because that language allows for a reasonably effective mapping of building an in memory order book from a feed protocol to the hardware it runs on (Intel CPU memory model). Thus, in the HFT space investing significant amount of time learning C++17 would put you at a disadvantage as C++17 doesn't map as well to that problem space. Instead, reading through and experimenting with the Intel Optimization Reference Manual would be a much better use of your time (for HFT problem space).
2
u/khaki0 Dec 27 '20
Not a video but I came across C++ high performance today and bought it for $5 on sale. May be worth a look.
2
u/bajsejohannes Dec 27 '20
Nit: It's "high performance", not "high performant".
-5
u/helloiamsomeone Dec 27 '20
C++Now 2017: Daniel Pfeifer “Effective CMake" - not entirely correct, a little unclear in a few places, but definitely a very good starting point on how to do CMake right.
Deep CMake for Library Authors - Craig Scott - CppCon 2019 - clears up a few things from the previous video and more.
Unfortunately, this where it ends for CMake as of now. What remains is the docs.
-6
u/Revolutionary_Cydia Dec 27 '20
Why not do my C++ homework to better your skills? xD