Intuition about performance is unreliable, and asymptotic analysis can hide what matters. Why is iterating an array faster than a linked list? “Pointers” is only half the answer. The CPU fetches 64-byte cache lines, so touching element zero of an array pulls the next 15 integers into L1 for free, while linked-list nodes are scattered across the heap. L1 is about a nanosecond, main memory about 100. “Big O said both were O of N, and Big O was hiding the part that actually mattered.”

So profile instead of guessing. In a flame graph, find the widest bar and ask why. Profile allocations too, because in garbage-collected languages the function that looks slow is often just triggering collection. The cost is “almost never where you assumed”: usually a helper called 4,000 times in a forgotten loop, or an N+1 query. Then benchmark before and after the change.

This is a special case of Things that are hard to keep doing well usually lack a metric: without the number, “optimization” can’t be told apart from making the code uglier.

Caveat: benchmarks lie too. Microbenchmarks miss cache and I/O effects of the real workload, and noisy runs make small wins invisible or invented. The number has to come from something close to production conditions.

Key Quotes

  • “If you can’t produce a number showing it got faster, you didn’t optimize anything. You made the code uglier and effectively told yourself a bedtime story.” (08:54)
  • “Blaming the framework is free, and nobody can disprove it at a standup. Profile it instead.” (08:22)

Related: