|
simplicity are everywhere. They spawn innumerable bugs and cost millions of man-hours 鈥
often, just to get marginal gains in the use of some resource much less expensive than
debugging time.
Disturbingly often, premature local optimization actually hinders global optimization (and
hence reduces overall performance). A prematurely optimized portion of a design frequently
interferes with changes that would have much higher payoffs across the whole design, so you
end up with both inferior performance and excessively complex code.
In the Unix world there is a long-established and very explicit tradition (exemplified by Rob
Pike's comments above and Ken Thompson's maxim about brute force) that says: Prototype,
then polish. Get it working before you optimize it. Or: Make it work first, then make it work
fast. 鈥楨xtreme programming' guru Kent Beck, operating in a different culture, has usefully
amplified this to: 鈥淢ake it run, then make it right, then make it fast.鈥
The thrust of all these quotes is the same: get your design right with an un-optimized, slow,
memory-intensive implementation before you try to tune. Then you tune systematically,
looking for the places where you can buy big performance wins with the smallest possible
increases in local complexity.
It's worth pointing out that you don't have to optimize what you don't write. The most
powerful optimization tool in existence may be the delete key.
Finally, it is almost never worth doing optimizations that reduce resource use by merely a
constant factor; it's smarter to concentrate effort on cases where you can reduce average-case
runtime or space use from O(n2) to O(n) or O(n log n), or similarly reduce from a higher
order. Linear performance gains tend to be swamped by the exponential effect of Moore's
Law 鈥 the smartest, cheapest, and often fastest way to collect those gains is to wait a few
months for your target hardware to become more capable.
Rule of Diversity: Distrust all claims for 鈥渙ne true way鈥.
Even the best software tools tend to be limited by the imaginations of their designers.
Nobody is smart enough to optimize for everything, nor to anticipate all the uses to which
their software might be put. Designing rigid, closed software that won't talk to the rest of the
world is an unhealthy form of arrogance.
Therefore, the Unix tradition includes a healthy mistrust of 鈥渙ne true way鈥 approaches to
|