3

I'm a team-leader/feature-architect that emerged from a developer position, so I have coding experience and a lot of the things being evolved now a days were implemented by me in the first place. Now to the point: Reviewing some code for the sake of refactoring (and some nostalgia) I've found a bunch of places that could be optimized, so as an exercise I gave myself 2 days to explore and improved a lot of stuff. After running a benchmark I found out that the general module performance had improved about 5%.

So I aproached some colleagues (and the team I run) and presented my changes. I was surprised by the general impression of "micro-optimization". If you do look at every single optimization, then yes, they are micro, but if you look at the big picture...

So my question here is: When is an optimization no longer considered "micro"?

user229044
  • 232,980
  • 40
  • 330
  • 338
Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • 2
    Would it have made sense to ask "Could I have gained more performance by optimizing the architecture of the program?" Just a thought... – user314104 Mar 11 '13 at 19:59
  • This will be a long discussion (so maybe not suited for SO) but first of all, be a leader...by doing your teams job you're not leading them, you better ask the team to have a list of things they would like to have refactored, have them prioritze that list (where you can have your say) and then you manage that list to get the issues resolved. – rene Mar 11 '13 at 20:00
  • 1
    **When a optimization is no longer “Micro-optimization”** When it yields measurable performance benefits in the real world. Pretty much end-of-story. – user229044 Mar 11 '13 at 20:01
  • What does 5% performance improvement mean? Some operations take 5% less time? A benchmark exercising the code paths you optimized is 5% faster? Or a realistic benchmark of the entire code program became 5% faster? In any case, 5% seems insignificant (though it may be useful in some cases). I think there are many cases where a *single* optimization widely considered "micro" could have such an effect (at the scope where the optimization applies that's optimized). –  Mar 11 '13 at 20:01
  • 1
    @meagar I don't know about other people, but that's not how I use the term. Optimizing memory layout for cache utilization (e.g. using an array instead of a linked list, even though only sequential access is needed) can easily have significant effects, but I still count it as a micro optimization. It's more about the level at which the change is applies than about the effect. –  Mar 11 '13 at 20:03
  • *Five percent?* A factor of 1.05? [*Here's a factor of forty-three. Times. Not percent.*](http://stackoverflow.com/a/927773/23771) If you're browsing through the code for things you could speed up, you could call it micro-optimization. I call it guessing. Learn how to do it by *finding out* what the opportunities are, not by guessing. Then, pass on the skill, and you'll be a leader. – Mike Dunlavey Mar 12 '13 at 00:37

2 Answers2

2

Whether an optimization is micro or not is usually not important. The important stuff is whether it gives you any bang for the buck.

You wrote you spend two whole working days for a 5% performance increase. Did you spend those days wisely? Was those things you fixed the "most slow" part of your application, or at least those most easy to fix performance issues? Did your changes made you reach your performance target (that you didn't do before)? Does 5% performance matter at all in your case? Usually you want something like 100% or 1000% increase if you figure out that you need to improve your performance.

Could you perform your optimizations without disturbing readability and/or maintainability of the code?

Besides, what other costs did those optimizations render? How much regression test were you required to perform? How many new bugs did you create?

I know, this looks more like questions than an answer, but those are the kind of questions that should rule your decision to make an optimization or not.

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
0

Personally, I would differentiate between changes that lead to a reduction in algorithmic time or space complexity (from O(N^2) to O(N), for example) and changes that speed up the code or reduce its memory requirements but keep the overall complexities the same. I'd call the latter micro optimizations.

However, keep in mind that while this is a precise definition it should not be the only criterion for deciding whether a change is worth keeping: Reduced code complexity (as in difficulty to understand) is often more important, especially if speed and memory requirements are not a major cause of concern.

Ultimately, the answer will depend on your project: For software running on embedded devices the rules are different than for stuff running on an Hadoop cluster.

Florian Brucker
  • 9,621
  • 3
  • 48
  • 81