Skip to content

Composer Autoloader Optimization Analyzer

Analyzer IDCategorySeverityTime To Fix
autoloader-optimization⚡ PerformanceHigh5 minutes

What This Checks

Validates that Composer's autoloader is optimized for production performance by checking for classmap optimization and authoritative classmap configuration.

Why It Matters

  • Performance Impact: Unoptimized autoloaders can slow down every single request by 10-30% as PHP searches through PSR-4 and PSR-0 rules
  • Production Critical: This check only runs in production and staging environments where performance matters most
  • Bootstrap Speed: Optimized autoloaders improve application bootstrap time significantly by converting namespace rules into fast classmap lookups

Laravel applications with many classes benefit the most from autoloader optimization. Without it, every class load requires filesystem checks and rule processing, adding measurable latency to each request.

How to Fix

Quick Fix (2 minutes)

Run the optimization command during deployment:

Before (❌):

bash
# Deploying without optimization
composer install
php artisan optimize

After (✅):

bash
# Deploy with autoloader optimization
composer install --optimize-autoloader
# OR run after install
composer dump-autoload -o

Proper Fix (5 minutes)

For maximum performance, implement authoritative classmap mode in your deployment pipeline:

Best Practice:

  1. Add to composer.json:
json
{
    "config": {
        "optimize-autoloader": true,
        "classmap-authoritative": true
    }
}
  1. Update deployment script:
bash
# In your deployment script (deploy.sh, CI/CD pipeline, etc.)
composer install --no-dev --optimize-autoloader --classmap-authoritative
php artisan config:cache
php artisan route:cache
php artisan view:cache
  1. Verify optimization:
bash
# Check if optimization is active
php -r "
\$classMap = include 'vendor/composer/autoload_classmap.php';
echo 'Classmap entries: ' . count(\$classMap) . PHP_EOL;
\$realPath = include 'vendor/composer/autoload_real.php';
echo 'Authoritative: ' . (strpos(file_get_contents('vendor/composer/autoload_real.php'), 'setClassMapAuthoritative(true)') !== false ? 'YES' : 'NO') . PHP_EOL;
"

Environment-Specific Configuration:

php
// bootstrap/app.php or service provider
if (app()->environment('production', 'staging')) {
    // Autoloader should already be optimized via composer.json config
    // This is just a runtime verification
    if (!file_exists(base_path('vendor/composer/autoload_classmap.php'))) {
        logger()->warning('Autoloader classmap not found - performance will be degraded');
    }
}

ShieldCI Configuration

This analyzer is automatically skipped in CI environments ($runInCI = false) and only runs in production and staging environments.

Why skip in CI and development?

  • Autoloader optimization checks are not applicable in CI
  • Local/Development/Testing environments don't need optimized autoloader (developers work with unoptimized for easier debugging)
  • Production and staging should have optimized autoloader for performance

Environment Detection: The analyzer checks your Laravel APP_ENV setting and only runs when it maps to production or staging. Custom environment names can be mapped in config/shieldci.php:

php
// config/shieldci.php
'environment_mapping' => [
    'production-us' => 'production',
    'production-blue' => 'production',
    'staging-preview' => 'staging',
],

Examples:

  • APP_ENV=production → Runs (no mapping needed)
  • APP_ENV=production-us → Maps to production → Runs
  • APP_ENV=local → Skipped (not production/staging)

References