in reply to Re: Re^2: Micro optimisations can pay off, and needn't be a maintenance problem (I don't believe it)
in thread Micro optimisations can pay off, and needn't be a maintenance problem
Thank you. That clears things up quite nicely to my mind.
A "micro optimization" is where you take a small operation (hence "micro") and make it run a bit faster (in hopes of making your program run faster). This is nearly doomed to be quite disappointing (as far as that hope is concerned).
So let's look at your optimizations (not in quite the same order as you listed them).
- Constantising parameter access.
- Removal of temporary variable usage.
- Re-coding of if, for(;;), while statements into their modifier forms
- [...] manually in-lining two trivial functions
Yes, these are micro optimizations.
- Moving invarient expressions, sub-expressions and statements from inside loops to outside.
No, this is not a micro optimization. Instead of making a tiny operation a bit faster, you are reducing how many times you run that tiny operation. So, this still has the disadvantage of the operations being tiny (so the percentage of the total run time being affected is likely quite small), but it has the advantage of instead of reducing this run time by something like 20%, you are instead cutting it by some large fraction. If the loop was being iterated 100 times, then you've cut the run time 100 fold.
The affect on the total run time is still likely to be relatively small, simply because the tiny operation is unlikely to constitute a large fraction of the total run time. If it, for example, was 10% of the total run time, then you might speed up the run nearly a full 10%.
- Common sub-expression elimination.
I'm not quite sure what you mean by this. It might be a micro optimization or it might be similar to the previous item.
- Merging of consecutive loops and/or nested loops into single loops or grep or map forms.
(Emphasis mine.) Here we have a mix of micro optimizations and very non-micro optimizations. Changing the nesting of loops is an important optimization technique. It is the type of thing were you can cause the entire body of a loop to be run a small fraction of the number of times that it used to be run.
The bodies of the loops could account for a huge percentage of the original total run time and you can reduce how many times they get run by a huge fraction. This is the kind of thing that can make programs run 10s or 100s of times faster.
I'm sorry that I can't take the time right now to analyze the changes in detail. For now I'll assume that this explains things. If others take time to study this in more detail, I will be happy to see it and interested in their findings.
Thank you very much, BrowserUk, for going through the effort to present this information.
- tye
|
|---|