In this article, we take a look at Optimization phase in a detailed manner.
The Optimization phase builds on the inputs received from the Pre-Optimization phase and looks at ways and means of implementing the optimization steps to increase performance.
There are two distinct parts to the Optimization phase, the first part is the initial implementation with respect to coding and code reviews. The second part is aimed at identifying trends and looking at specific instances to improve.
Implementation Level Activities
i) APIs: At this stage decisions are made with respect to the actual APIs or libraries to be used. For e.g. whether to go for IPP library and the specific Windows APIs to use. The idea here is to look at it in terms of performance and not in terms of functionality alone.
ii) Evaluation of Loops: This activity looks at the various loops and tries to reduce the level of looping involved. Can a three level nested loop be reduced to two-level of nesting? Can loops be combined together? Can we replace recursion with loops?
iii) Exception Handling: Exception Handling is a useful mechanism which comes with an overhead in terms of performance. At this stage it can be verified whether exception handling is really required in certain APIs or not. Especially APIs invoked recursively or in a loop need to be visited during this activity.
iv) Evaluation of the Data Variables: In this activity the idea is to look at data variables in terms of whether it is the right data variable for the activity. This is especially important for STL classes such as vectors, lists, maps etc. where selection of the right variable can impact the performance significantly. The other point to consider might be whether the data variable is required or whether it can be moved to a better location.
v) Reuse Opportunities: One of the essentials for optimization both code as well as performance is to ensure that there are not multiple ways of doing the same thing and the most optimal way is used always. So this step is to evaluate the code and product from that aspect.
All the activities listed in this part can be efficiently implemented in a project using code review checklists specifically designed for performance tuning.
Trend and Outlier Analysis
Trends depict a pattern within an application that is not obvious on a case by case basis. For e.g. if there is a deterioration of the performance with time, that cannot be visualized by looking at a single run of the software.
Outliers depict specific instances which do not conform to the performance requirements for the software. For e.g. if the processing of a single image takes more time compared to other datasets, then this image represents an outlier.
The key to doing Trend and Outlier Analysis is often the first step of identifying the Trends and Outlier. For this purpose graphs are perfect tools which help identifying these.
Other interesting graphs for performance optimization are Resource Utilization Graphs, Breakup Analysis Graphs & Relational Graphs.
Fig 1: Resource Utilization Graph
Using the above Resource Utilization Graph, it is clear that the system performs in a linear manner till around 800 to 900 users, and then there is an exponential increase in the processor usage. This might be a good indicator to go define the performance parameters of the system. This is a good example of a trend analysis based on the Resource Utilization Graph. The other benefit of this graph is it helps define the threshold limits like the max number of users the system can support.
Fig 2: Outlier Analysis
The above graph depicts the memory usage per number of images. Four of these instances indicate sudden increased memory requirement. These are nothing but outliers. In this particular case, this occurred as there were gaps in these datasets leading to internal interpolation leading to additional number of images and hence the increased size. This is an example of outlier analysis.
Artifacts from Optimization Phase
Some sample artifacts from the Optimization Phase are:
1) Regular performance reports.
2) Focused Code Review Reports and Checklists.
3) Performance Graphs
4) Identification of Trends and Outliers.
5) Interdependence between components in terms of performance.
Morals of the Story
1) Trend Analysis helps in identifying non-obvious patterns within the software system.
2) Outlier Analysis helps in identifying peaks and troughs in the system.
3) Graphs are a very handy tool for performance optimization.