Improving the Magento 2 Admin Performance
Emakina’s Alexandre Jardin used Blackfire to find a performance improvement in the Magento 2 back-office. PR submitted and approved by the Core.
Alexandre Jardin is a Senior Developer at Emakina. In December, he came across some slowness in the Magento 2 Admin. By using Blackfire, he quickly found how to improve the code, and submitted a Pull Request on Magento/Magento2 so the whole community could benefit from it.
His Pull Request has been approved, merged, and his work is released as part of v2.3.1.
Finding the bottleneck
Last December, some of my colleagues told me that their Magento 2 project was sometimes slower when they tried to access several pages in the back-office. Especially the list of CMS pages whereas other pages were loaded normally.
Therefore, I decided to profile our application with Blackfire.
I started my investigations by checking the calls graph, and the class \Magento\Theme\Model\PageLayout\Config\Builder was immediately highlighted since the method getConfigFiles() was responsible for no less than 90% of the total execution time! And if we look closer, we can see that this method is called twice by getPageLayoutsConfig().
The method getPageLayoutsConfig() has two callers in this context: \Magento\Cms\Model\Page\Source\PageLayout::toOptionArray() and \Magento\Cms\Model\Page\Source\CustomLayout::toOptionArray().
PageLayout used a property to avoid unnecessary calls to the getPageLayoutsConfig() method by storing its result on the first call while CustomLayout extends PageLayout and inherits this behavior from it. The problem is that the two instances of these PHP classes will not share the value of their property. It means that there were two independents caching systems.
Following this observation, I added exactly the same logic in the Builder class rather than its callers to be sure that the most time consuming operations are performed only once.
The numbers speak for themselves.
This improvement affects only admin panel, but in multiple places: CMS pages, CMS blocks, CMS widgets, categories and products.
Contributing to Magento/Magento2
Finally, contributing to Magento is a nice and satisfying experience. Everything you need to know is explained in the Code Contributions guide. You benefit from a really robust process where a bot will allow you to automatically deploy test instances and where other contributors will help you finalize your contribution. It’s also rewarding to be able to integrate your own code into a huge project like Magento which is a solution widely used when it comes to e-commerce.
Emakina is Blackfire Enabled
Emakina has been one of the most advanced users of Blackfire since years. Thanks to their expertise in improving the performance of their customer’s applications, including by using our tool, we’ve awarded them the Blackfire Enabled label, and are proud to work with them on a regular basis.
Blackfire has been part of our toolbox for years now. We started using it by manually profiling pages on our oldest Magento site. It’s after having fixed many performance bottlenecks that we decided to go further with Blackfire. First with basic assertions, then with assertions related to non-regression tests on issues which have been already addressed. These tests were still run manually, so we decided to implement automated tests after each integration and production deployment. This allowed us to identify performance issues prior to their release on production.Alexandre Jardin
We give a high priority to the performance of our developments. That’s why we aim to consolidate our current Blackfire’s integration, and use it systematically in all our PHP projects.