Skip to main content

Fast. Faster. Composer 2.0

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

A few days ago Jordi announced the first dev build of Composer 2.0. I immediately went and downloaded it. Since version 2.x should be a lot faster, I thought it is a good idea to test it against a current Magento 2 project I am working on. I was a bit disappointed first because Composer failed with quite a few errors like that:

magento/product-community-edition 2.3.3-p1 requires magento/composer
~1.5.0 -> satisfiable by magento/composer[1.5.1, 1.5.0] from composer repo
( but magento/composer[1.0.3, 1.1.0, 1.2.0,
1.2.2, 1.0.2] from composer repo ( has higher
repository priority. The packages with higher priority do not match your
constraint and are therefore not installable.
See for details and assistance.

Thankfully Nils took some time to explain to me in detail what is happening and why. In Composer 2.x repositories are treated as canonical, meaning once a package is found in one canonical repository, Composer will stop looking further. Obviously, this is faster than going through each and every repository and check which versions are available and merge all the information together. However, this can lead to a situation where the version you actually want to install is not part of the first canonical repository found and that will lead to the mentioned error. Ideally, this should not happen, but it can as we can clearly see above.

Luckily it took Jordi and Nils less than a day to provide a fix for this issue. With the latest 2.x-dev build of Composer you can mark repositories in your composer.json file as non-canonical by setting the canonical flag to false, like this:

"repositories": [
"type": "composer",
"url": "",
"canonical": false

This will now make Composer check for all Magento packages on Packagist as well as on Magento's repository to find all possible versions available, as Composer does in version 1.x.
Besides setting canonical:false on the Magento repository, I had to do the same for our company internal Satis instance since we cache the Magento packages there as well. After that, I could start conducting a few tests. It's important to understand that the speed differences occur only when running composer update. Once you have the composer.lock file in place, you won't see any difference in speed. That means before every test run I had to remove the composer.lock file as well as the vendor folder.

These are the results:

PHP 7.3 / Composer 1.x: 6.20m
PHP 7.3 / Composer 2.x: 2.46m

PHP 7.4 / Composer 1.x: 4.44m
PHP 7.4 / Composer 2.x: 2.45m

If you are still on PHP 7.3 you gain the most, Composer 2.x is about 2.5 times faster than Composer 1.x. If you are already on PHP 7.4, Composer 2.x will be about 1.8 times faster. This is really impressive!

If you haven't tested Composer 2.x-dev so far, please give it a try. Report any issues that you encounter to make sure we get the best possible version of Composer 2.x soon!