Knowledge Guide
HomeSystem DesignMental Models & Systems Thinking

Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)

Know the machine you run on

Mechanical sympathy (Martin Thompson, borrowing racing driver Jackie Stewart's phrase) is the idea that you don't have to be a hardware engineer, but you write dramatically faster code when you understand how the hardware actually behaves. The dominant fact: not all memory is equal — each level of the hierarchy is orders of magnitude slower than the one above.

Memory hierarchy from register/L1 (~1ns) down through RAM (~100ns), SSD, disk, to cross-continent network (~150ms), each a latency cliff
Memory hierarchy from register/L1 (~1ns) down through RAM (~100ns), SSD, disk, to cross-continent network (~150ms), each a latency cliff

The consequences that change how you write code

The mental model

When something is slow, ask "where does this data live, and am I fighting the cache / the prefetcher / the disk's sequential nature?" Often the fix is a better memory layout, not a better algorithm.

Takeaways


Re-authored for this guide; memory-hierarchy diagram hand-authored as SVG. Follows Martin Thompson's "mechanical sympathy" and the latency-numbers canon. See also: Capacity Estimation (latency numbers), (Concurrency) Memory Model & false sharing, How Indexes Work (pages).

🤖 Don't fully get this? Learn it with Claude

Stuck on Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)** (System Design) and want to truly understand it. Explain Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing) from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Mechanical Sympathy — Know the Machine (Caches, Locality, False Sharing)** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes