Cotya/magento-composer-installer

Improving M1 Composer Performance: Can Composer be configured to ignore Magento's PSR-0 classes?

Closed this issue · 2 comments

I notice that despite Composer being the secondary autoloader for Magento, it still tries to find file paths for the Magento classes. In all of my environments, this drastically impacts load time.

Because Magento will handle class loading first, I thought I could get by with this:

  "autoload": {
    "psr-0": {
      "": [
        "webroot/app/code/local",
        "webroot/app/code/community",
        "webroot/app/code/core",
        "webroot/lib"
        ]
    }

And then executing: composer install --no-ansi --no-interaction --no-progress --optimize-autoloader.

This helps Composer map the Magento classes to their file locations following the same fallback order that Magento does, because Composer isn't looking for the files, performance is improved.

However, it seems that this may actually interfere with Magento's autoloading despite composer being the fallback method. It seems that all of the above was in vain.

The outstanding problem that I need to resolve is: Can we avoid Compose trying to determine the file locations of Magento classes in order to improve performance.

It looks like --classmap-authoritative may be the secret. My understanding of this option is that it instructs Composer to only attempt to load classes that have been mapped.

For anyone stumbling across this in a Google search, do not implement the PSR-0 config shown in my original post.

So far this is testing best with the script shown below. I prefer dump-autoload to handle the --classmap-authoritative because the install may not always trigger a refresh of the class map if no new modules have been implemented.

composer install --no-ansi --no-dev --no-interaction --no-progress
composer dump-autoload --no-ansi --no-interaction --classmap-authoritative

However, you may be able to get by without the dump-autoload:

composer install --no-ansi --no-dev --no-interaction --no-progress --classmap-authoritative

Could you please provide some numbers, how much the load time is increased on a warmed opcache, and also on which php version you are?
last time I checked this was nearly not measurable.