Low latency C++ application development tips

 

Introduction

This is a blog post to summarize the talk hosted by Carl Cook [1].

Tips


tips details power_point
understand what is C++ doing compiler explorer can help this
simple cpu configuration disable hyperthreading can speed up, sorting as an example
how fast is fast 2.5us
low latency programming techniques when in doubt, use brute force, by Ken Thompson
slowpath removal ensure that error handling code will not be inlined
template-based configuration aim to removes branches, codes that won't be used
lambda function is good if you know at compile time which function is to be executed

memory allocation allocations are costly, do it from another thread if you cannot avoid it
exceptions in C++ do not afraid to use it, but not for control flow
prefer templates to branches
multi-threading in hot path, avoid multi-threading, if you need to use, try no to share data but copy it
try not to have data lookups put the data you needed close together, pair up one to one data
measurement template we care about branch-misses and cache-misses
hash map discussion std::unorder_map, google hash map, a hybrid solution
noinline use this hint for the compiler and measure the outcome before production
keeping the cache hot
don't share L3 avoid multiple cores usage per CPU
placement new can be slightly inefficient some version of gcc / clang will do null pointer checking
define your placement new as a workaround
small string optimization
std::function may allocate new memory this could be slow, you can try inplace_function
std::pow can be slow
measure your system why it is important
tools in the market
measure your system example setup for low latency systems measurement






power point [2]

Reference

[1] C. (2017, October 8). CppCon 2017: Carl Cook “When a Microsecond Is an Eternity: High Performance Trading Systems in C++.” YouTube. https://www.youtube.com/watch?v=NH1Tta7purM

[2] When-a-Microsecond-Is-an-Eternity-Carl-Cook-CppCon-2017.pdf. (n.d.). Google Docs. https://drive.google.com/file/d/1w15HPCPw95hE62k46lMaPXGuT4BpO5ps/view?usp=sharing

Comments