phpsymfonycomposer-phpblackfire

Improve Composer\Autoload\includeFile in Symfony


I have made Blackfire test on my Symfony 2.8 project and it shows that most of the time (more than 50%) is used by 435 calls of Composer\Autoload\includeFile

Any suggestions how to improve it? I am using php composer.phar dump-autoload --optimize after I clear cache for prod.

I use APC for metadata and query cache for doctrine and my app.php file looks like this:

<?php

use Symfony\Component\HttpFoundation\Request;

/**
 * @var Composer\Autoload\ClassLoader
 */
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/bootstrap.php.cache';

// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.
/*
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
*/

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Solution

  • This function looks like this:

    function includeFile($file)
    {
        include $file;
    }
    

    So this is not the issue with Composer itself. There's nothing to optimize here. You're just including a lot of files.

    Anyway, take a closer look at your app.php.

    First, you've wrote I use APC (...), and then pasted code snippet containing this:

    // Enable APC for autoloading to improve performance.
    // You should change the ApcClassLoader first argument to a unique prefix
    // in order to prevent cache key conflicts with other applications
    // also using APC.
    /*
    $apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader);
    $loader->unregister();
    $apcLoader->register(true);
    */
    

    I would suggest to follow this hint and uncomment these a few lines of code.

    Also there may be possible optimizations in APC configuration.