Summary of hft low latency technique


* Write determinstic code

1. use Compile time polymorphism using CRTP (Curiously recurring template pattern)



Maps with static values which can be evaluated in compile-time ▻ Compile-time configuration which replaces runtime flags with templated values ▻ Rearranging and/or statements order to move the more predictable values first ▻ Of course: constexpr all the things!

* Warm up the cache


real order can be very rare, but real order is the critical path that we want it to be the fastest. So do some cache warm up when we are not really generating the order. 

But when executing order, we don't want the dummy order effect the total result.

Don't use if. The compiler will do branch prediction, it may not doing the execution by code order, and if most of the case it not inside the if, it will skip it first. And make the real situation even slower.

The main rule for cache warming is not using if.

The right solution:


* Tailor-made data structures for specific use cases
small size map optimization:

small size sort, bubble sort efficiency is better than the quick sort.
* Performance measureement

tips:

1. taking timestamp is costly


Reference:

1. https://youtu.be/_0aU8S-hFQI High-Frequency Trading and Ultra Low Latency Development Techniques From Nimrod Sapir


To Do:

What is system call and why it cost a lot

Comments

Popular Posts