edit

Optimization: Your Worst Enemy

Posted by Curt Hibbs Sat, 25 Mar 2006 08:25:00 GMT

Joseph M. Newcomer tells us something that we all know, but is all to easy to forget ignore: avoid premature optimization. He backs it up with a lot of details and finally concludes:

Optimization matters only when it matters. When it matters, it matters a lot, but until you know that it matters, don’t waste a lot of time doing it. Even if you know it matters, you need to know where it matters. Without performance data, you won’t know what to optimize, and you’ll probably optimize the wrong thing.

The result will be obscure, hard to write, hard to debug, and hard to maintain code that doesn’t solve your problem. Thus it has the dual disadvantage of (a) increasing software development and software maintenance costs, and (b) having no performance effect at all.

2 comments

Comments

  1. Isaac Gouy said about 10 hours later:

    Michael Jackson’s Rules on Optimization
    Rule 1. Don’t do it.
    Rule 2. (for experts only) Don’t do it yet.

    “Principles of Program Design” by M.A. Jackson, Associated Press 1975

    Michael Jackson provides a very original perspective on software development.

  2. Warren said 2 days later:

    It isn’t that simple. Sometimes you know you’re going to run into performance problems. There’s a reason that people trying to predict the weather buy supercomputers and code in pedal-to-the-metal FORTRAN.

    Sometimes, you know in advance you’ve got to fit your functionality into a small memory footprint, especially in embedded systems.

    Using a database is a performance optimizion over flat files or trying to squeeze it all into ram. And sometimes you know you’ll need some sort of SQL database. You don’t reallly suggest that people build their business apps but leave all the database/sql stuff to version 2.0?

    If you’re coding the Java VM you probably can’t use a garbage-collected language, you probably have to use C or maybe C++.

    Sometimes you know in advance—in those cases, optimization in the beginning is not “Premature”.

    And yes, go do read Michael Jackson’s book. He makes a unique contribution and is not a singer.

Comments are disabled