An article from the pen of Paul Cavallaro about system programming. It is an overview of some common optimization techniques and neat tricks for doing “systems programming” -– whatever that means today.
It provides some tools for improving performance in your own applications, or at least make it easier to understand why performance sensitive code is doing what it’s doing.
The article discusses in depth:
- Cache lines & false sharing
- The magic power of 2: division is slowaloo
- Repurposing top bits
- Lock striping
False sharing problem has been written about fairly extensively, but the basic idea is that physical memory on a machine isn’t infinitely granular, i.e. you can’t just read a byte.1 Instead, when you want to read a single byte of memory, the processor will pull in and cache not just that byte, but the surrounding data as well, on the assumption that it will likely be used too. This unit of data that gets read and cached is called a “cache line”, and is essentially the smallest piece of memory that can be accessed.
While this is nowhere near an exhaustive list of the most common systems programming tricks, hopefully it whets your appetite to learn more.
All of the examples we went over over are also on github at paulcavallaro/systems-programming. Written in C++. Good read!
[Read More]