Optimization Tip 1: Make sure you’re measuring what you think you are

Sunday, February 5th, 2006

Optimization is a subject fraught with witchcraft, voodoo, and superstition. Far too often it is done badly and pseudoscientifically. The first rule of optimization is that you can’t do it without measuring . Almost any guess you make about performance is at best irrelevant and often actively harmful. A common technique is to write a benchmark that runs the piece of code you’re trying to optimize several thousand times, and prints out the time it takes to run. Then tune until the time comes down.

They’re at least ten reasons why this technique fails more often than it succeeds (forgetting to account for HotSpot initialization, optimizing a piece of code in which the program spends a trivial amount of time, etc.) but recently I encountered an 11th: the benchmark may not be exercising the code you think it is. This turns out to be surprisingly common, and the more complex the code is, the more likely this is to occur.

Undocumented Changes in Java 6 Mustang: IOError

Thursday, February 2nd, 2006

At some point, a new java.io.IOError class was added to Java 6. This is “Thrown when a serious I/O error has occurred.” No further explanation is offered.

This is not listed as a change in the JDK 6 documentation; and I haven’t noticed this addition in any JSRs, though I could easily have missed one. Can anyone explain where this new class has come from and what is likely to cause it be thrown?