The distance table you should carry in your head
Before diagnosing anything, calibrate on the costs, because the ratios are what make some designs obviously wrong.
| Operation | Rough order of magnitude |
|---|---|
| Function call, arithmetic | Nanoseconds |
| Main memory access | Roughly 100 nanoseconds |
| Fast local SSD read | Tens of microseconds |
| Same-datacentre network round trip | Hundreds of microseconds |
| Database query over that network | Milliseconds |
| Cross-region round trip | Tens to hundreds of milliseconds |
The spans between rows are the point. A network round trip is roughly a thousand times a memory access; a cross-region call is a million times an arithmetic operation.
Key idea: these ratios mean an optimisation's value depends almost entirely on which row it removes. Eliminating one database query is worth more than making a million arithmetic operations twice as fast. That is why the six causes below are ordered as they are: the ones that touch the slow rows dominate almost everything else.
Each cause has a recognisable signature, and learning the signatures means you can form a hypothesis before opening the profile.

