On the right a comparison of the two profiles. The previous and the current one. The blue blocks indicate improvements with the wall clock time in seconds. A simple change with huge effects. Of course it’s also possible to view the profile not in comparison mode.
Further improvements could be to run the collection load once for all products instead of 21 times separately. Handling the problem at the top of our red path, is mostly a better idea because each sub function follows. Because in this case each product could have different configurable attributes configured, this is maybe not the best idea. Be aware this is not the standard list.phtml Magento template. In contrast to this template, the getSortedAttributes function is core Magento functionality and could be a quick win for different Magento projects.
This issue was mainly a CPU problem, but you can also have other factors that could cause problems. It’s a good idea to inspect all tabs provided. Memory, Network, Http, Queries, etc.. A good example are import /export scripts. These could easily cause CPU problems, but also memory problems. Let me give you an example of an other case. This time about a Magento’s varien core file.
When importing product images with one of Magento’s cronjobs, an ‘out of memory’ error was thrown. I decided to use Blackfire’s CLI this time, because cronjobs could be time consuming. Especially when handling import scripts. This profile was generated with the free version of Blackfire, so some tabs could have disappeared.