Interview question
How does autoloading with Composer affect PHP performance, and how do you optimize it? Composer autoloading PHP performance को कैसे प्रभावित करता है?
Answer
Composer's default autoloader (PSR-4) resolves class names to file paths dynamically. In production, this can be optimized into a fast, precomputed lookup.
# Development - flexible but slower
composer dump-autoload
# Production - optimized classmap, much faster
composer dump-autoload --optimize
# or during install/update
composer install --optimize-autoloader --no-dev| Mode | How it resolves classes |
|---|---|
| Default | Runtime PSR-4 namespace-to-path logic |
| Optimized (--optimize) | Precomputed classmap array, direct lookup |
The --optimize-autoloader flag is a standard part of production deployment scripts alongside opcache and config caching.
Composer का default autoloader (PSR-4) class names को dynamically file paths में resolve करता है। Production में इसे optimize किया जा सकता है।
composer dump-autoload --optimize
# या
composer install --optimize-autoloader --no-dev| Mode | Classes कैसे resolve होती हैं |
|---|---|
| Default | Runtime PSR-4 logic |
| Optimized | Precomputed classmap, direct lookup |
Was this answer clear?