Book Deep-Read · A Philosophy of Software Design · Chapter 20

Designing for Performance

A Philosophy of Software Design · Ch 20 · Designing for Performance · Ousterhout · 2nd ed 2021

中文 →

What is this chapter about?

You tap an app and it spins for three seconds — somewhere, a piece of code is "too slow." Many programmers believe that to be fast, code has to be twisted and hard to read. This chapter's author says the opposite: most of the time, clean and simple code is already the faster code.

A curious fact first

The author once tore down and rewrote a piece of his team's code that packs up messages, aiming to make it faster. The new version ran nearly twice as fast — and it was shorter. Here, fast and simple turned out to be the same thing.

Why it was hard before

Two common extremes both go wrong. Some people squeeze for speed from day one and turn the code into a tangle. Others ignore speed entirely, and when the system finally crawls they discover it is a little slow everywhere — with no single spot to fix.

How it works, intuitively

What it buys you / how to choose

Day to day, write simply and pick the faster option when it costs nothing. When you truly need speed, measure where it's slow first, then make the most-traveled road short and straight. One honest cost: redesigning that main road often means tearing up existing structure, which is real work — so do it only after measuring shows it's worth it.

Remember it in one line

Simple is usually fast; to go faster, measure first, then straighten the road most traveled.

Want the orders of magnitude between operations, the concrete critical-path redesign recipe, the RAMCloud rewrite, and why Google says "write it simply and optimize later" is often wrong? → Switch to the deep read