In an earlier post (A five-step process for optimization) we suggested that identifying optimization candidates is an important step in making an optimization. It's important because choosing good candidates helps to minimize the amount of technical work changing and testing the optimized system.
This post introduces some techniques to choose candidate functions for optimization.
Not surprisingly, having good information is vital. Guessing where to start work is not the way to go...proper timing measurements and analysis of your code saves you from wasting time and effort optimizing the wrong thing.
Firstly, optimization candidates should be on the worst case path and have a high contribution to it (a high W-SelfCT in RapiTime terminology). Typically (although not always!) we find that there are relatively few functions that have a major contribution to the worst case path).
Don't be fooled into thinking that just because something gets executed frequently that it is on the worst case path.
But what else is useful and how do you rank them so that you get high gains for minimal effort? Some more things to consider:
- If a function appears multiple times in the worst case path, then any optimization you make to that function you gain multiple times. Saving 100 cycles in a function is easy, saving 1000 is harder. So if you can save 100 cycles in a function that's called 10 times, then you get your 1000 cycles easily. In RapiTime terminology, look for high values of W-Freq (worst case frequency).
- Small simple code can be easier to change than large or complex code that may require more effort to understand. Look for high values of W-SelfED (Execution time density of code on the worst case path).
- Changing complex code also carries a greater risk of introducing bugs, and if the code is not well isolated from other parts of the system then an small functional change to a function might have unintended effects elsewhere.
- It is useful to understand the implications for testing: can a change in one function be validated more easily than another?
Our diagram might help you to rank optimization candidates so that you focus your time on the right ones.