Profile before you optimise, and the ninety seconds it takes

The cost of running a profiler is ninety seconds and the cost of not running one is two days spent on three per cent of the request.

$ php -d xdebug.mode=profile 
     -d xdebug.output_dir=/tmp/prof 
     -d xdebug.start_with_request=trigger 
     -S 127.0.0.1:8080 -t public

$ curl 'http://127.0.0.1:8080/products/8814?XDEBUG_TRIGGER=1'
$ kcachegrind /tmp/prof/cachegrind.out.14022

trigger mode is what makes this usable: profiling every request produces gigabytes and slows everything by a factor of five, and profiling one request costs nothing else. The result is almost never what anybody predicted, which is precisely why the ninety seconds is worth spending when the answer feels obvious — the obvious answer is the one nobody checked.