Leanpub Header

Skip to main content

C++ Data-Oriented Design

Cache-Line Mechanics, SoA Layouts, SIMD Vectorization, and Memory Access Optimization for High-Performance Systems

C++ Data-Oriented Design
This book is 100% completeLast updated on 2026-10-12

Your CPU is not slow. Your data is in the wrong place. Every cache miss your hot loop pays is not a hardware limitation, it is a layout decision that was never made consciously. The pointer your code chases, the struct field your loop skips over, the heap allocation that landed three megabytes from the last one: these are the real performance bottlenecks in CPU-bound systems, and none of them show up in a complexity analysis. This book teaches you to see your data the way the hardware sees it, measure what it costs, and redesign it so the memory system works with your code instead of against it.

Minimum price

$29.00

$49.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
About

About

About the Book

Learn to eliminate cache miss bottlenecks and memory stall penalties with confidence using measured, verified data layout engineering, guided by a systems programmer’s playbook for struct design, access pattern optimization, and concurrent data structure architecture across CPU-bound production systems.

Key Features

  • Master core data-oriented design disciplines used across real production systems, from cache line mechanics and struct field ordering through ECS component pools, flat trees, and lock-free pipelines
  • Learn to eliminate hidden performance losses including pointer chasing, heap fragmentation, false sharing, strided access patterns, and object-oriented drift that silently undoes optimization work
  • Build provable throughput without assuming it, using perf, Cachegrind, Intel VTune, and a Google Benchmark CI pipeline with baseline comparison and static layout assertions

Book Description

Most engineers reach for algorithmic optimizations when their code is slow, unaware that the same pointer-connected heap layout or the same AoS struct that looked fine in testing will stall the CPU on memory the day the working set actually grows. This book closes that gap, providing the practical knowledge of cache line mechanics, data layout transformation, and concurrent system design needed to build software with measured throughput guarantees, not assumed ones.

You will begin at the silicon level, understanding what cache lines physically are, how the memory hierarchy imposes latency on every access that misses it, and why the pointer-connected layouts that object-oriented design naturally produces are structurally hostile to the hardware. You will measure the problem before touching a single struct, using hardware performance counters to quantify cache miss rates, memory stall fractions, and instructions per cycle across your real hot paths.

The book walks through the full arc of production data-oriented engineering: struct field ordering and padding elimination, hot and cold data separation, Array of Structures to Structure of Arrays conversion that unlocks compiler auto-vectorization, AoSoA hybrid layouts, Entity Component Systems with dense archetypal storage and generational handles, flat array replacements for pointer-based trees and lists, slot maps that provide O(1) stable-handle lookup without pointer indirection, software prefetching, cache tiling, false sharing elimination, per-thread work partitioning, and lock-free ring buffer design where memory layout determines coherence traffic as much as the algorithm does. Three applied chapters walk a scene graph, a high-frequency trading order book, and a particle system through complete transformations with hardware counter measurements at every step.

Whether you are optimizing your first cache-bound simulation loop or hardening a production system that must sustain low latency under real concurrent load, this book provides actionable layout techniques and measurement discipline for performance that holds under live workloads.

What You Will Learn

  • Define pointer chasing, false sharing, and strided access precisely and distinguish them from ordinary performance noise
  • Build real SoA layouts and ECS component pools without relying on assumed-efficient object-oriented patterns
  • Deconstruct cache miss overhead into working set, access pattern, and allocation-driven components
  • Evaluate AoS, SoA, and AoSoA layouts per workload before committing to a storage design
  • Verify layout correctness against hardware counters and benchmark baselines before trusting a result
  • Recognize and eliminate silent working set inflation without guessing at root cause
  • Know when a data structure is provably cache-friendly versus merely contiguous
  • Design per-thread partitioning and lock-free pipelines for bursty, contention-prone concurrent workloads

Who This Book Is For

This book is for C++ systems engineers, performance engineers, and senior developers building or optimizing throughput-critical software across game engines, simulation systems, financial infrastructure, and any domain where the gap between theoretical hardware throughput and measured application performance demands a hardware-level explanation. No prior knowledge of data-oriented design or CPU microarchitecture is assumed.

Table of Contents

  • The Hardware Reality: Why Object-Oriented Layout Betrays the CPU
  • Data Layout Fundamentals
  • Structure of Arrays versus Array of Structures
  • Entity Component Systems and Data-Driven Architecture
  • SIMD and Vectorization Through Layout
  • Flat Data Structures and Pointer Elimination
  • Memory Access Patterns and Prefetching
  • Data-Oriented Design for Concurrent Systems
  • Applying Data-Oriented Design to Real Systems
  • Profiling, Validation, and Sustaining Data-Oriented Codebases; Appendices

Share this book

Author

About the Author

Weston Ashgrove

Weston Ashgrove is a C++ quant trading developer who builds the parts of a trading system that cannot be allowed to be wrong: order books, matching logic, and the concurrency and memory-layout work underneath them. He has a simple rule for latency-critical code: nothing is true until it has been profiled, fuzzed, and replayed. That rule runs through this book, from the first order book benchmark to byte-identical crash recovery. He writes for engineers who ship and debug these systems, and he skips the theory that never survives contact with real order flow.https://x.com/dxled_dc

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub