Static Content Generation gets too slow after upgrading to Magento 2.4.5

Recently I worked on a project which was being implemented in Magento 2.4.5 version. This project was based on Magento Cloud and after making a deployment there, I noticed that the deployment took more than 1 hour to complete and I found it very intriguing.

Commonly, when the project is in good health of performance, the deployment takes no more than 15~20 minutes but taking more than 1 hour is way too much to be acceptable.

You may ask me: but, Tiago, obviously no one likes to wait too much for a deployment to complete, but what’s the problem with having a deployment taking more than 1 hour exactly?

Imagine if you have an issue in production with Magento checkout and the customers are not able to place orders. The stakeholders will be desperate because they are losing money and your boss will be bugging you way too much to get that fixed. Well, let’s say you have a fix ready to be pushed to production however, it will take more than 1 hour to get this fix in place.

This is a good example of why we always should work on streamlining the deployment process to minimize the time it takes so that you don’t need to worry about waiting too much time to get a fix in place when needed.

The first thing I noticed is that there were more than 20 themes on this project, which makes the process slower naturally but more than 1 hour is still intriguing for me. Here’s the result of a static content generation before finding a solution for that.

php-fpm:/var/www/html$ bin/magento setup:static-content:deploy

Deploy using quick strategy
frontend/Magento/blank/en_US            2373/2373           ============================ 100%   2 secs
adminhtml/Magento/backend/en_US         3090/3090           ============================ 100%   3 secs
frontend/Magento/luma/en_US             2390/2390           ============================ 100%   2 secs
adminhtml/Magento/spectrum/en_US        3090/3090           ============================ 100%   2 secs
frontend/ayo/ayo_default/en_US          2581/2581           ============================ 100%   2 secs
frontend/osv/b2b/en_US                  2373/2373           ============================ 100%   3 secs
frontend/ayo/ayo_home6/en_US            2583/2583           ============================ 100%   4 secs
frontend/ayo/ayo_home6_rtl/en_US        2586/2586           ============================ 100%   7 secs
frontend/ayo/ayo_home3_rtl/en_US        2586/2586           ============================ 100%   10 secs
frontend/ayo/ayo_home9/en_US            2585/2585           ============================ 100%   17 secs
frontend/ayo/ayo_home2/en_US            2583/2583           ============================ 100%   26 secs
frontend/ayo/ayo_home11/en_US           2585/2585           ============================ 100%   40 secs
frontend/ayo/ayo_home1_rtl/en_US        2584/2584           ============================ 100%   59 secs
frontend/ayo/ayo_home7/en_US            2584/2584           ============================ 100%   1 min
frontend/ayo/ayo_home15/en_US           2585/2585           ============================ 100%   1 min
frontend/ayo/ayo_home16/en_US           2612/2612           ============================ 100%   2 mins
frontend/ayo/ayo_home5/en_US            2583/2583           ============================ 100%   3 mins
frontend/ayo/ayo_home8/en_US            2584/2584           ============================ 100%   4 mins
frontend/ayo/ayo_home3/en_US            2584/2584           ============================ 100%   5 mins
frontend/ayo/ayo_home4_rtl/en_US        2586/2586           ============================ 100%   7 mins
frontend/ayo/ayo_home10/en_US           2585/2585           ============================ 100%   9 mins
frontend/ayo/ayo_home2_rtl/en_US        2586/2586           ============================ 100%   11 mins
frontend/ayo/ayo_home7_rtl/en_US        2588/2588           ============================ 100%   14 mins
frontend/ayo/ayo_home4/en_US            2583/2583           ============================ 100%   17 mins
frontend/ayo/ayo_home13/en_US           2584/2584           ============================ 100%   21 mins
frontend/ayo/ayo_home14/en_US           2584/2584           ============================ 100%   25 mins
frontend/ayo/ayo_home12/en_US           2592/2592           ============================ 100%   29 mins
frontend/ayo/ayo_home5_rtl/en_US        2586/2586           ============================ 100%   34 mins

Execution time: 11726.365982056
php-fpm:/var/www/html$

As you can see above, the first theme took 2 seconds to complete while the last one took 34 minutes. For each theme being generated, an additional time was added to the process. Man, that was weird.

Well, the first thing we should do is look for quality patches provided by Magento to see if there’s something related to the error we’re having. I made this research for a while and I found the following one: ACSD-46815.

https://github.com/magento/quality-patches/blob/master/patches/os/ACSD-46815_2.4.5_v2.patch

https://experienceleague.adobe.com/docs/commerce-knowledge-base/kb/support-tools/patches/v1-1-20/acsd-46815-static-content-deploy-fails-when-using-compact-strategy.html?lang=en

Apparently, this patch addresses errors with the static content generation and it should make sense to apply it to the project.

As the project is based on the Magento Cloud architecture, I just created a file named .magento.env.yaml and added the following content to it.

stage:
  build:
    QUALITY_PATCHES:
      - ACSD-46815

With this file in place, in the next deployment, the patch will be applied automatically to the code. However, if you’re working locally and would like to test it before pushing anything to either staging or production environments, you can run the following:

vendor/bin/ece-patches apply

This will apply the patches listed on this file and you’ll be able to test it locally.

After applying this patch to the project, here is the result of the same command.

php-fpm:/var/www/html$ bin/magento setup:static-content:deploy

Deploy using quick strategy
frontend/Magento/blank/en_US            2373/2373           ============================ 100%   < 1 sec
adminhtml/Magento/backend/en_US         3090/3090           ============================ 100%   1 sec
frontend/Magento/luma/en_US             2390/2390           ============================ 100%   0
adminhtml/Magento/spectrum/en_US        3090/3090           ============================ 100%   1 sec
frontend/ayo/ayo_default/en_US          2581/2581           ============================ 100%   0
frontend/osv/b2b/en_US                  2373/2373           ============================ 100%   0
frontend/ayo/ayo_home6/en_US            2583/2583           ============================ 100%   1 sec
frontend/ayo/ayo_home6_rtl/en_US        2586/2586           ============================ 100%   0
frontend/ayo/ayo_home3_rtl/en_US        2586/2586           ============================ 100%   0
frontend/ayo/ayo_home9/en_US            2585/2585           ============================ 100%   1 sec
frontend/ayo/ayo_home2/en_US            2583/2583           ============================ 100%   0
frontend/ayo/ayo_home11/en_US           2585/2585           ============================ 100%   0
frontend/ayo/ayo_home1_rtl/en_US        2584/2584           ============================ 100%   1 sec
frontend/ayo/ayo_home7/en_US            2584/2584           ============================ 100%   0
frontend/ayo/ayo_home15/en_US           2585/2585           ============================ 100%   0
frontend/ayo/ayo_home16/en_US           2612/2612           ============================ 100%   1 sec
frontend/ayo/ayo_home5/en_US            2583/2583           ============================ 100%   0
frontend/ayo/ayo_home8/en_US            2584/2584           ============================ 100%   1 sec
frontend/ayo/ayo_home3/en_US            2584/2584           ============================ 100%   0
frontend/ayo/ayo_home4_rtl/en_US        2586/2586           ============================ 100%   0
frontend/ayo/ayo_home10/en_US           2585/2585           ============================ 100%   1 sec
frontend/ayo/ayo_home2_rtl/en_US        2586/2586           ============================ 100%   0
frontend/ayo/ayo_home7_rtl/en_US        2588/2588           ============================ 100%   1 sec
frontend/ayo/ayo_home4/en_US            2583/2583           ============================ 100%   0
frontend/ayo/ayo_home13/en_US           2584/2584           ============================ 100%   0
frontend/ayo/ayo_home14/en_US           2584/2584           ============================ 100%   1 sec
frontend/ayo/ayo_home12/en_US           2592/2592           ============================ 100%   0
frontend/ayo/ayo_home5_rtl/en_US        2586/2586           ============================ 100%   1 sec

Execution time: 15.775093078613
php-fpm:/var/www/html$

See? 15 seconds is waaaaay faster, isn’t it?

Remember, in order to get the advantages of the ece-patches for your project, you must install it via composer:

composer require magento/quality-patches

You can find more details in the quality patches repository.

https://github.com/magento/quality-patches

I hope this helps you as much as helped me.

Leave a comment