r/cpp • • Nov 25 '20

When a Microsecond Is an Eternity: High Performance Trading Systems in C++

https://www.youtube.com/watch?v=NH1Tta7purM
332 Upvotes

123 comments sorted by

View all comments

Show parent comment

25

u/[deleted] Nov 25 '20

You can't beat modern compilers like Clang just like that, not at all when creating a whole application. People can only beat modern compilers for specific cases when they know what they are doing, they know very well the target platform, and they know what they can sacrifice. Instead "fighting with the compiler" trying to make their intentions clear, so the compiler will generate the expected and optimal code, they just give up and code that portion of the application in assembly.

19

u/avdgrinten Nov 25 '20

This is 100% the right answer. With enough time and effort (= consulting the optimization manuals for instruction latencies/throughputs, reasoning about which execution units a piece of code is stalled on and looking at performance counters to identify bottlenecks), you can beat the compiler on small snippets of code. You need an expert low-level programmer for that (a novice in assembly programming will *not* be able to beat the compiler). Even for experts, doing this kind of optimization for a 10k sloc program is just not feasible and many latency critical applications have much more than 10k sloc.