Pick Low-Hanging Fruit

Finally, it’s time to optimize. We’ll start by looking at the flat profile in KCachegrind and sort it by Self time, as shown in the figure.

images/src/optimization_session_start_flat_profile.png

Object#parse_col comes first, taking more than half a second of execution time. The function itself is not that slow, but we call it 150,000 times. Also, it calls two slow functions: <Class::Date>#parse and Regexp#match.

We should definitely concentrate our optimization on this group of three functions. Why is column parsing so slow? It’s not because it takes too much time to parse one row. We do that in about 3 microseconds, but repeat that 150,000 times (50,000 rows multiplied ...

Get Ruby Performance Optimization now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.