Magento 2 - Faster composer install
Anybody that has sat through an initial composer install of Magento 2 will know it’s slow. Very slow. Unbelievably slow in fact. The main reason for this is the sheer number of dependencies which it pulls in. I decided to do some profiling and see if I could improve performance.
Development Setup
I’ve only recently started looking into Magento 2. To kickstart the process I decided to use a basic Vagrant set-up that I currently use with Magento 1. I’m using a Centos 7 base box that is provisioned with Ansible. This is running as a 4GB Virtual Box on Mac OS X.
Default Install of Magento 2
In order to check just how slow it was, and confirm it wasn’t my imagination or impatience, I first needed to profile the installation. In order to make it a fair test, I first removed the files and cleared the composer cache.
1 2 3 4 5 6 |
[vagrant@vagrant magento]$ composer clear-cache [vagrant@vagrant magento]$ rm -rf vendor/ [vagrant@vagrant magento]$ composer install --no-progress --profile --prefer-dist ... [14.4MB/855.58s] Generating autoload files [14.8MB/884.81s] Memory usage: 14.8MB (peak: 102.98MB), time: 884.81s |
As you can see it took the best part of 16 minutes to fetch and install all the dependencies! Achieving a fast deployment pipeline is important. Especially during the initial development stages where you’re still smoothing the edges of your process. Waiting over a quarter of an hour is therefore not going to fly.
Prestissimo
Performing some research, I came across the composer plugin prestissimo. The purpose of the plugin is to fetch the dependencies in parallel thus reducing the overall time taken. I read some debates over whether it was truly ‘parallel’, but for our purposes this isn’t really relevant. All that really matters is whether or not time to completion is improved. Since that is our objective, I decided it was worth checking out.
Following the instructions on the official github page, I therefore installed the plugin for global usage:
1 |
[vagrant@vagrant magento]$ composer global require hirak/prestissimo |
Prestissimo Install of Magento 2
With the plugin installed, it’s time to perform our new profile. To ensure a fair test I ran the exact commands I ran previously:
1 2 3 4 5 6 |
[vagrant@vagrant magento]$ composer clear-cache [vagrant@vagrant magento]$ rm -rf vendor/ [vagrant@vagrant magento]$ composer install --no-progress --profile --prefer-dist ... [14.8MB/656.62s] Generating autoload files [15.2MB/684.19s] Memory usage: 15.18MB (peak: 19.98MB), time: 684.19s |
As you can see the overall time is now just under 11 and a half minutes. Still pretty slow, but a significant improvement none the less.