in reply to Re: Golfing and Sprinting
in thread Golfing and Sprinting

Another key is 'micro-' (or 'nano-', which I started using because some tiny optimizations in Perl made what I was used to calling 'micro-optimization' seem huge in comparison because Perl can have much bigger overhead than something like C).

I wouldn't much mind many discussions of optimization that are premature if they covered real optimization techniques. Instead, most premature optimization discussions end up dealing with really tiny tasks.

This is problematic because, 1) being tiny, they are usually a part (tiny part) of a wide variety of algorithms so people overestimate their importance ("I can apply this speed-up all over the place!"). And 2) being tiny, the difference between what Benchmark.pm measures and what you can actually gain from using them is huge so people focus on "four times as fast!" and don't even think about "adds up to less than 1% of the run time of my script".

So, premature optimization is a bad habit but can be fun and educational in a perverse sort of way. And in very rare situations, micro-optimizations can actually pay off (at least a little bit). So I can cut people slack for playing with premature optimization as a learning exercise if it isn't micro-optimization. And I can see attempting micro-optimization if you've done the profiling to show that this micro-operation is actually adding up to a significant portion of your run time (that is, if the optimization isn't premature).

But I will always find premature micro-optimization to be something to be critical of when I see it (especially if I don't see anyone else pointing out that the numbers aren't nearly as exciting as they appear and the techniques aren't automatically the best choice in real code).

In that other thread, we see examples of both: people suggesting that the fastest code should be used in future code and people thinking that a 4x speed-up in a micro-optimization could end up with a 4x speed-up of total run time.

So, in theory, premature nano-optimization could be educational. In practice, I don't usually see interesting discoveries made and I very often see enthusiastic adoption of 'the winner' to the point of any other method being 'corrected' because it isn't 'efficient'.

- tye