14.1 Build first, then optimize

14.1.1 Identifying bottlenecks

""“Focusing on optimizing small portions of your app before making it work fully is the best way to lose time along the way, even more in the context of a production application, where there are deadlines and a limited amount of time to build the application.”""

When your furniture takes 2 months to cross the ocean, it doesn’t matter whether you have an electric screwdriver

It’s hard to know where the bottlenecks will be until your app is working

And there’s no point optimising until you know where the bottlenecks are…

14.1.2 Do you need faster functions?

""“Of course a function running twice as fast is a good thing, but think about it in context: for example, how many times is this function called? We can safely bet that if your function is only called once, working on making it twice as fast might not be the one function you would want to focus on”""

But, what if your single-call function holds everything else up?

14.1.3 Don’t sacrifice readability

Possible restructurings:

  • high-level language (R/python) to low-level language (C++/rust)

  • one package to another

  • single to parallel implementation

Optimisation trade-off against:

  • maintain-, read-, searchability

Example: compare C++ code for computing mean with R code for the same