Kayavak / Work backwards
Concepts
Work backwards
Most teaching goes from cause to effect. These start at the other end: a result the books measured that looks wrong, and the chain of causes behind it. Each step is folded, so reason it out before you open it; each links to the chapter that teaches it. 6 so far.
- Every request took 48 milliseconds on localhostFifty requests to a server on the same machine took 48 ms each, until one socket option made them take 3.
- The same two columns, 16 times faster in the other orderAn index on (placed_at, status) answered a query in 4.24 ms; the same two columns as (status, placed_at) answered it in 0.27 ms.
- The same loop, 30 times slower in a different orderWidening 500 boxes by a pixel took 54.9 ms one way and 1.9 ms another, with exactly the same reads and writes.
- Same Big-O, 144 times slowerSumming four million numbers took 144 times longer in one layout than another, though both are O(n).
- One click, 64 calls to a database that was downA single user request reached a failed database 64 times, though no layer retried more than three times.
- Sorting the data made the loop 7 times fasterThe same loop over the same million bytes ran 7.3 times faster once the bytes were sorted, and only 30% faster when the compiler was left alone.