Here we will describe how to improve standard Magento 2 compilation in order to make it almost twice faster.
In several compilation components, such as Application code, Area, Interception and Interception Cache generators, Magento 2 scans filesystem looking for PHP classes, dependencies, etc.
We assumed that core Magento 2 modules do not change often and we can cache their list to avoid unnecessary filesystem scans.
In files:

  • setup/src/Magento/Setup/Module/Di/App/Task/Operation/ApplicationCodeGenerator.php
  • setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php
  • setup/src/Magento/Setup/Module/Di/App/Task/Operation/Interception.php
  • setup/src/Magento/Setup/Module/Di/App/Task/Operation/InterceptionCache.php

we added cache logic to the method doOperation().

With some additional code, we’ve created a module from this files. You can download it here.


Copy Eleanorsoft folder to app/code/.
Run setup:upgrade.
Run setup:di:compile.
After compilation, you should see a folder var/di_cache/ with 4 (or more) files. This is the actual cache. From now your compilation process will use these cached lists instead of scanning the whole filesystem.

During testing, we noticed 40% to 50% acceleration of the compilation process.

Note 1: these caches contain only core files. All custom modules will be scanned each time as usual.
Note 2: if you upgrade Magento 2, delete these files because core modules could change during the upgrade.

Related Post

Docker and Magento: Test and...

In this article, we will describe one of the ways to run Magento 2 on Docker. Docker is a...

Search for ALL words in...

By default Magento 2 QuickSearch feature searches for at least one word from the entered...

Install Magento 2 on Windows...

This article describes one of the ways to setup Magento 2 on Windows or Linux. This...

PayPal error: We can’t...

There is a bug with PayPal checkout on early versions of Magento 2. Users may see error...