vova19 Oct 2025 13:42

There is advice that classmap autoloading is faster than PSR-4 because it avoids filesystem lookups. In practice, is this worth doing in production?

Replies (5)
alex_petrov19 Oct 2025 13:48

composer dump-autoload --optimize creates a classmap from PSR-4 declarations. You get classmap lookup speed without manually maintaining a classmap. Run this as part of your production deploy.

0
petr_sys19 Oct 2025 13:58

With OPcache enabled, the autoload files are cached in memory anyway. The difference between PSR-4 and optimized classmap in production with OPcache is negligible. Optimize because it is easy, not because it will make a measurable difference.

0
dmitry_kv19 Oct 2025 14:30

The --optimize flag also merges all autoload files into fewer files, reducing the number of includes on startup. On apps with many packages this matters slightly for cold start time.

0
nphp19 Oct 2025 16:19

Do not run --optimize on development. It means new classes are not discovered until you re-run composer dump-autoload. The default PSR-4 discovery handles new files automatically.

0
vova19 Oct 2025 16:41

composer install --no-dev --optimize-autoloader is the standard production deploy invocation. No dev dependencies, optimized classmap, minimized autoload overhead.

0
Write a reply
Markdown. ```php blocks are runnable.