• Cache computed results (memoize1)
  • Do work at compilation time instead of runtime2
  • Delay computation (put in lambda)
  • Index data for quick retrieval

Optimization Techniques.

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.

Fast Ruby

  • 1

    Donald Michie in 1968 https://en.wikipedia.org/wiki/Memoization

  • 2

    Not available in Ruby. In a language like Lisp, you can compile a function!