# Autoloader Optimization Analyzer
Category | Severity | Time To Fix |
---|---|---|
🚀 Performance | Major | 5 minutes |
Class: Enlightn\Enlightn\Analyzers\Performance\AutoloaderOptimizationAnalyzer
# Introduction
This analyzer ensures that you have enabled the Composer autoloader optimization in a non-local environment.
Due to the way PSR-0/4 autoloading rules are defined, the Composer autoloader checks the filesystem before resolving a classname conclusively.
In production, Composer allows for optimization to convert the PSR-0 and PSR-4 autoloading rules into classmap rules, making autoloading quite a bit faster.
# How To Fix
# Level 1 Optimization
To enable level 1 optimization, you can use the -o
or the --optimize-autoloader
flag in your deployment script like so:
composer install --prefer-dist --no-scripts --no-dev -q -o
Alternatively, you can also set the optimize-autoloader
config in your composer.json
file to true
:
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
# Level 2 Optimization
To enable level 2 optimization (higher performance), you can use the -a
or the --classmap-authoritative
flag in your deployment script:
composer install --prefer-dist --no-scripts --no-dev -q -a
Level 2 optimization works the same as level 1 with the difference that it assumes the classmap to be "authoritative". This means that if a class is not found in the classmap, it will not attempt to look in the filesystem (unlike level 1 optimization). This can further enhance performance for class_exists
function calls.
Runtime Class Generation
With level 2 optimization, if a class is generated at runtime, it will cause "class not found" issues. So be careful to only enable this if you are sure that there are no runtime classes being generated by your application or its dependencies.
# Skip Condition
This analyzer is skipped if your application is in a local environment.