Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

townsendmusic's avatar

Composer "Generating optimized autoload files" very slow

Hey,

Asking on here as a fresh because I have seen a number of historic posts about a similar issue however the solutions haven't helped me or my colleague.

Its a large repo but other colleagues using Mac and Linux OS's have no problem. Just myself and another colleague both running on Mac OS Sonoma. The "Generating optimized autoload files" consistently takes between 300 and 400 seconds to run. On the same project on other machines its about 20s.

See below trace (I've omitted non relevant updates)

[19.7MiB/8.30s] Installing dependencies from lock file (including require-dev) [20.8MiB/8.30s] Verifying lock file contents can be installed on current platform. [21.1MiB/8.31s] Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run composer update or composer update <package name>. [26.3MiB/60.37s] Generating optimized autoload files [51.2MiB/455.23s] Warning: Ambiguous class resolution, "FPDF" was found in both "/home/tmstores/www/app/functions/Services/External/FPDF.php" and "/home/tmstores/www/vendor/iio/libmergepdf/tcpdi/tcpdi.php", the first will be used. [72.0MiB/479.08s] > Illuminate\Foundation\ComposerScripts::postAutoloadDump [91.3MiB/485.32s] > @php artisan package:discover --ansi

The previous solution was to register packagist in the repos with https "repositories": { "packagist": { "type": "composer", "url": "https://packagist.org" } }

This sadly doesn't work.

has anybody any ideas?

0 likes
10 replies
jlrdw's avatar

I suggest backup first.

If your dependencies are correct:

  • delete vendor folder
  • delete composer.json and .lock again back these up first
  • composer clearcache
  • composer selfupdate

Then run composer install.

But verify your dependencies by looking over the various composer.json files involved. Jot down stuff needed with pencil and paper.

3 likes
townsendmusic's avatar

For anybody new coming across this. the fix for me was a combination of things, before which the generating optimised autoload files took over 260s.

First adding : "https://packagist.org" to repositories in composer.json.

"repositories": [ { "type": "composer", "url": "https://packagist.org" } ]

then

composer clear-cache

composer update

then

composer install -vvv --profile

(took about 115 secs) ran after this and its now 20s

composer install -vvv --profile

3 likes
townsendmusic's avatar

Although the above solution helped originally, the issue some came back.

I found that my anti-virus was causing the some delay for each file that was being checked as part of the auto loader. Adding the project directory and the process of the IDE to the exclusion list of the AV resolved the issue fully :)

7 likes
smily's avatar

In my case it was related to windows defender.. what helped was:

Add whole directory of your app to windows defender Exclusions. You can also move your projects in project directory and add projects to exclusion.

15 likes
wall-e's avatar

Thanks! @smily! Never knew windows defender was slowing it down. I excluded the whole project folder of mine as you suggested and the time drastically reduced from minutes to seconds!

2 likes
Schober86's avatar

composer dump-autoload -o

fixed it for me

1 like
fredysiswanto's avatar

In my case, trying to disable Windows Defender processes is much faster, taking less than 2 minutes. If Windows Defender is on, it takes more than 10 minutes.

not best solution, but working on my projects.

soban1's avatar

in my case any of these sloutions cant work.

Please or to participate in this conversation.