Composer classmap vs PSR-4: performance and when to switch
There is advice that classmap autoloading is faster than PSR-4 because it avoids filesystem lookups. In practice, is this worth doing in production?
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.
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.
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.
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.
composer install --no-dev --optimize-autoloader is the standard production deploy invocation. No dev dependencies, optimized classmap, minimized autoload overhead.
```php blocks are runnable.