You have probably asked yourself the question of when or what to optimize in your app. It is not an easy question to answer because there are many factors involved in making the decision. There are always tradeoffs in software development and it is not any different for optimization — sorry to burst your bubble.
Since optimizing your code is not always a win-win situation, you’ll have to evaluate whether or not you and or your team should do it. Here are some things to consider when making the important decision to optimize your code or not.
What Is the Bottleneck?
Before thinking about optimization, make sure you have correctly identified the bottleneck(s) within your code base. I am not talking about a hunch here. What I mean is you have detailed reports on where your app is spending the most time doing work. In addition, you need to make sure there are no external factors that can be affecting the performance of your code. For example, if the part of the code that is slow is using a third-party service and it is the service that is slow in giving your code the result, you can’t optimize that.
What Is the Change in Complexity for the Optimization?
One of the biggest tradeoffs for optimization is making the code more complex. In exchange for a performance bump, you are giving up code readability, which can slow down future progress in development. Code readability is definitely important and it can make the difference between a project being sustainable or not. You and your team will need to decide whether the change in complexity is going to be manageable for the long-term.
Do You Have the Right Metrics?
This point ties together with identifying the proper bottleneck(s). When gathering your data, you want to make sure you have the right data. You might need to gather data for each operation within a subroutine to get the data you need. For example, you have a subroutine that creates a data file from a third-party service. This would probably require making an API call, parsing the result, then finally writing the file. You would want to gather the performance of each of those parts individually to identify a performance problem.
How Important Is the Performance Increase?
Let’s take a step back and look at what you would gain from the performance increase. Not all performance issues need to be optimized in real software. So, what you need to consider is how impactful will the performance increase be for your users or customers. A webpage loading under one second is definitely not the same as speeding up a database access by a few microseconds. A fast loading webpage definitely will impact your customers more than a negligible speedup in database access.
What Is the Targeted Platform?
Where your code runs will matter in deciding what you need to optimize. For example, if your code is for a break detection system of a car then you want it to be as fast as possible. On the other hand, giving up code readability and maintainability for a performance bump doesn’t always make sense for a web or mobile application.
I hope this post was helpful to you. If you found this post helpful, share it with others so they can benefit too.
What else do you consider when deciding when to optimize?
To get in touch, you can follow me on Twitter, leave a comment, or send me an email at steven@brightdevelopers.com.