Techniques to speed up
- Cache computed results (memoize1)
- Do work at compilation time instead of runtime2
- Delay computation (put in lambda)
- Index data for quick retrieval
To find what to optimize, we have to instrument. Use things like profiler, to find out which method / function got called how many times.
In order to profile, we need to set up a set of test examples, benchmark, to represent the typical work we do.
Run the code against the benchmark with profiler, find hot/critical spots. Then optimize.
What if we already used the best algorithm possible and performance is still low? We can find the most used parts of the program. Apply micro optimizations.