Fixing the algorithm
My preferred approach to improving performance is—always—fixing the algorithm. Look at it this way—if we need 1 time unit to process one data item, and the algorithm is O(n2), we need 10,000 time units to process an input of size 100. If you fine-tune the code and speed up the operation by 50% (which is an excellent result), the code will need 5,000 time units to do the job. If you, however, change the algorithm to O(n log n), it will need in the order of 1,000 time units or less. Even if processing one item takes 100% longer than in the original code, the whole process will run in, say, 2,000 time units.
An algorithm with lower complexity will beat an algorithm with higher complexity, even if the latter executes its steps faster.
As it’s impossible to give one piece of advice that will fix all your problems, Chapter 3, Fixing the Algorithm, looked into different user stories. The first topic was responsive user interfaces (UIs...