Optimization Is Not Easy

Go to ludicrous speed!

If optimization was easy there would be no slow applications. Slow performance rarely has a single cause. Depending on the number of causes, optimization is a difficult goal. Using a consistent, and defined process needs be a critical part of any optimization effort.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%” -Donald Knuth

Optimization has a number of side effects, of which we must be aware. During optimization, many times, we must make trade offs. A classic optimization case is, trading processor heavy calculations in favor of using more RAM. Optimizing code can have the unintended effect of making code unreadable, and inflexible.

I mentioned before that Optimization is a difficult goal. I lied. The truth is optimization is not a goal, rather it is a process, also it is best handled as an iterative process. Using an iterative approach allows you to compare your results, and it gives you a better shot at isolating troubled areas. The worst approach you can have is to try tackle everything at once, because you will not be able to correlate the results to a specific change.

My personal process for optimization is pretty straightforward:

  • Observe, and Measure
  • Research
  • Change
  • Analyze
  • Repeat (If Necessary)

Once you have a chosen something to optimize the first task is to observe and measure a metric, such as number of operations during a particular action. Attempt to do some research, as to why a particular section of code. Once you have your researched as much as you need to, use your best judgment, and make a change you think will have a positive effect. After making the change analyze whether it performed better than you original measurements, if it did you are on the right path, if not you have just eliminated a potential path.

If you are not happy with the results of a round of iteration. If you continue the process eventually you will notice that you are seeing diminished returns. A few items can be cherry picked, with a simple rewrite of this procedure. If optimizing the easiest items do not achieve your goals, then the difficult work will commence. The same procedure will be followed, but the success rate of the iterations will drop.

Optimization is one of the core group of tasks many developers will need to confront. A consistent, and methodical process will provide a stable foundation to any optimization strategy. Many times optimization goals may not be met, or will require a significant amount of effort. Serious optimization does happen, but we must realize that it is not something that just happens, it requires directed, and methodical effort.

Post a Comment

Your email is never shared. Required fields are marked *

*
*
Profile Picture

About Ian Lintner


I am a software developer, mostly web,  in Des Moines, Iowa. I take a very opinionated stand concerning development, you will never regret a simple design or architecture. My education was at Drake University in Biology and Computer Science. Offline I am recently married to my wife Heather. I try my hand at many hobbies currently I am gardening till the snow comes in.



My Current Projects


Des Moines Twitter Trends