2

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);
Tom
  • 1,203
  • 3
  • 15
  • 35

1 Answers1

1

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.

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
  • OK, so only solution for this would be to have less files, which means less bundles. As for APC, what is weird in app.php file that if I uncomment those 3 lines I get worse times than without it. With these uncommented lines it takes 100ms more per request. – Tom Sep 14 '16 at 08:02