Dev Principles

Dev Principle #10: Do Performance Optimization When Needed

November 21, 2016

Donald Knuth is famous for saying “Premature optimization is the root of all evil.” There is a lot of good advice packed into that short statement.

The full context of this quote sheds even more light on why it’s important to think about optimization during development:

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%.

Now that we know the danger posed by premature optimization, what impact does this have on the software development process?

  1. The modern frameworks and languages that are available today go to great lengths to make sure they are running with performance in mind. Generally speaking, there is no need to worry about garbage collection of resources or keeping your memory footprint small after performing complex calculations. Those will be handled (and handled far better) by the frameworks and languages.
  2. The capacity of the servers that your apps run on have memory and disk space to spare, so there is no need for one letter variables and odd ternary operator tricks.
  3. Common tasks like database queries and asynchronous operations are now written out in a few lines of code. Your framework takes care of the rest – often with better performance than if you wrote it out from scratch.

By keeping these points in mind, you can focus on writing cleaner code that is easier to maintain. While keeping performance in mind will always be an important aspect of your solution, it should not be the driving force of your project unless absolutely necessary, given the general optimizations and machine power already at your disposal. The code you write may actually be less performant and could make it difficult to maintain.

What about the critical 3% of optimization mentioned above? Setting up profiling and benchmarking tools provides a great way to track where the bottlenecks that are causing performance issues are located in your code. There are plenty of performance analysis tools out there for the language you are working in. Additionally, services like loader.io and New Relic can help stress test your web sites and servers to see where your performance begins to suffer. Finally, you can set up monitoring on your database server to see where queries are performing poorly. Oftentimes these tests are easy to set up and can provide key places in which optimization is possible.

With all of the strides made in programming languages and frameworks, you can focus on writing good, clean, maintainable code. Let the underlying system worry about optimizing itself. You should only dig in and start doing performance optimizations when deemed necessary and after performance tests have shown you where to actually update.

assessing website performance with tests

Sean Patterson

Software Development Director

Sean Patterson is a Software Development Director at Fresh Consulting. By day he develops applications at Fresh with the motto "If you can dream it, I can build it." By night he's a java overlord (of the coffee persuasion), aspiring running junkie, spider killer for his wife, and silly daddy to his twin daughters.

You might also like...

17

Oct.

Dev Principle #11: DRY – Don’t Repeat Yourself

As the size and scope of a project increase, so does the complexity of the code base. One way to maintain and stabilize your code is to adhere to the “DRY” Principle: Don’t repeat yourself. #1: Use the DRY Principle to Decrease the Size of Your Code Base If you’re writing code to do the same … Continued

11

Nov.

Dev Principle #9: Start with a Skeleton to Test and Learn

Many developers have experienced being stuck in a “feature hole” – or worse yet, their project suffers the fate of “Death by Planning.” These are two of the reasons why we highly recommend building a skeleton of a project first. What is a Project Skeleton? Imagine that all the polishing and user experience of a … Continued

28

Oct.

Dev Principle #8: YAGNI – Ya Ain’t Gonna Need It

At first pass, building a comprehensive application or API library seems straightforward. You want to make sure that every possible scenario is covered for proper data coverage and that the user can do anything (however small) they want within the app. However, the ramifications of this approach can be larger than you think. This has led … Continued