REVIEW - The Art of Writing Efficient Programs - An Advanced Programmers Guide to Efficient Hardware Utilization and Compiler Optimizations Using C++ Examples


The Art of Writing Efficient Programs

An Advanced Programmers Guide to Efficient Hardware Utilization and Compiler Optimizations Using C++ Examples


Fedor G. Pikus


Packt Publishing (2021)




Paul J. Floyd


May 2023



Verdict: Highly recommended.

Quick disclaimer – I work for the same company as the author, but we work for different divisions on different continents.

I don’t remember exactly how I came across this book, possibly browsing online book shops. I ordered it as soon as I saw it.

Performance is the bread and butter of my job, so all sources of information are most welcome.

The book is written around C++ code efficiency. It should mostly also apply to C, but developers using other languages will benefit less. Writing efficient programs still mostly rhymes with C and C++. This book also has a fairly strong amd64 bent with some uses of inline assembler and profiling down to the opcode level. There are a few examples using aarch64 for comparison.

The book is made up of 3 sections. The first section covers the basics like why we need performance, how to measure performance and some fundamentals of hardware architecture. The compiler and the hardware do so many things these days that you need to have some grasp of what is going on in order to be able to optimize your code. There’s a bit of a digression explaining how Spectre worked as an example of how timing measurements reflect hardware cache and speculative execution activity.

The second section is about concurrency. More specifically it covers threads and how various locking mechanisms affect program efficiency. Pikus explains how thread contention affects scalability and covers several ways to improve on regular mutexes. These include spinlocks and lock free data structures.

The final section covers things that affect single threads. Various memory related topics are discussed – avoiding copies and allocations. Two chapters cover aspects of compiler optimization, and the book is rounded off with some broad-strokes advice on designing for performance. This includes some of the trade-offs that may need to be made such as information hiding.

There was one thing that I didn’t like in this book. That’s the code examples. They are printed on a gray background (OK) but with white line spacing (not so OK). I would have preferred something simpler and easier on the eyes like a simple box or begin/end horizontal lines and a different font.

My only problem now is to find the time try out some of the tools like LLVM Machine Code Analyzer.


Your Privacy

By clicking "Accept All Cookies" you agree ACCU can store cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

By clicking "Share IP Address" you agree ACCU can forward your IP address to third-party sites to enhance the information presented on the site, and that these sites may store cookies on your device.