Sunday, 11 October 2009

Item 55: Optimize Judiciously

Bloch gets this item so right! He includes some famous quotes about optimisation and of course the most well known one:

We follow two rules in the matter of optimisation:
Rule 1: Don't do it.
Rule 2: (or experts only). Don't do it yet.

But Bloch doesn't leave it there. He goes on to summarise the rules with "measure performance before and after each optimization attempt." We all know this, but how many of us actually do it?

Actually I've seen these rules put to bad use and Bloch covers that too when he points out that you should still be thinking about performance issues when writing code. The example I've seen is someone retrieving a lookup table from a database for each iteration through a dataset, rather than reading it once and caching it. At least that optimisation was straight forward.

The new information that surprised me a little was that it appear to be accepted that Java does not have a strong performance model. We all know Java is traditionally slow, but i must admit I thought performance had been greatly improved in recent years. Of course the “semantic gap” between what the programmer writes and what the CPU executes is far greater than in traditional programming language.

I almost didn't need to write a summary as the final paragraph of the item summarises it so well.

No comments:

Post a Comment