Blog Stats
  • Posts - 21
  • Articles - 0
  • Comments - 25
  • Trackbacks - 17

 

Premature Optimization

As Software Engineers, we need to be concerned about performance when we are building an application. Performance is a very legitimate concern for any non-trivial application, and it requires much thought and care. No matter how wonderful and functional the application is, if it is not performant it will turn users off very quickly. It is natural to want to optimize the code at all times. After all, we have been trained to think in terms of zeros and ones.

Loosely speaking, highly optimized applications are often hard to debug, maintain, and require more time to develop. This is because highly optimized code requires specialized knowledge or clever algorithms that might not be intuitive to everyone. This specialized algorithm often it is not susceptible to change and it is often very cryptic to understand. With modern software, changes in business requirements are inevitable.

Often people will have some preconceived notion as to how a certain type of code will behave in a cookie cutter way under a given condition. Software has been more complicated than ever. It is hard to predict the behavior of the software without actually testing it. On top of that, modern compiler’s optimization has been more intelligent than before. Writing clever code sometimes yields no benefit because the compiler will often optimize it, and it could possibly confuse the compiler in certain cases.

The point I am trying to make is that premature optimization often leads to cryptic code and more time to develop. The time might be better used to provide more functionality in software than trying to make some operation perform slightly faster. Of course, we all want our application to run as fast as possible, but without actually writing some code to test the performance under a specific load, it is hard to guess how the software will perform. People often attempt to optimize the code as they are writing it for the first time, which can be very time consuming and may provide no benefit. It is much easier to optimize the code after you run some profile on the code, and figure out the slow areas. If the business requirement changes and the optimized code is no longer needed, all the effort is wasted. It is best to apply all the optimization as needed at the last possible moment in the development to gain the maximum benefit, so the development time can be reduced. In order to accomplish this, the application’s architecture must be flexible enough. Which means proper abstractions and separations are required to make this possible.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Premature Optimization

Gravatar Remember what type of software app you are writing as well. Your time is the most expensive resource in software development. If you are writing enterprise applications, then as long as your app is scalable, you are okay; It's much cheaper to add hardware then it is to spend time optimizing. But if you are writing application software then you may have to put more time into performance since the hardware is beyond your control. 6/12/2006 7:13 AM | Todd

# re: Premature Optimization

Gravatar Yes, I completely agree with you. Since developer salary is the most expensive part of the project, optimize only areas are needed will save lots money and time. 6/12/2006 2:26 PM | Aaron Feng

# re: Premature Optimization

Gravatar A good rule of thumb for applying once profiled is that any optimization should be end user perceivable.

This really helps focus the team on the right kind of optimizations.



6/12/2006 9:11 PM | Greg Young

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Aaron Feng