Search code examples
phpsymfonycomposer-phpsymfony-2.8

symfony 2.8 optimization: do I still need to use APCClassLoader?


I need optimize my symfony in terms of speed. The hosting server is running php 7.x.x and opcache is enabled. apc_u extension is disabled but I could ask to enable it if really needed.

What I'm doing now is calling:

composer dump-autoload --optimize

whenever I deploy my app. That way, the app should already have all the mappings needed without having to iterate over the folders (right?). I'm wondering if ApcClassLoader could improve my performances if autoload_classmap.php is already well updated.

Here are my app.php first lines:

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();

long question short: could enabling ApcClassLoader improve my performances if autoload_classmap.php is already well updated?


Solution

  • Please read my answer here: Why use a PSR-0 or PSR-4 autoload in composer if classmap is actually faster?

    You have to evaluate whether or not dumping a classmap of all the classes in your application actually increases or decreases speed. If you have too many classes in the classmap dump, you end up moving a huge array from opcode cache into memory, which is both bad for the opcode cache (it takes some amount of memory, which might kick out other code), and for the amount of memory needed to run any script.

    As the general rule: If you optimize, measure anything you want to optimize before, then after you do something, and see if things improve.

    Also note that "optimize in terms of speed" is not a very exact description of what you want to improve. Is it response time for a single request? Or is it response time for a server under heavy load? Did you profile the application first in order to find out where the time is spent?

    You are asking a very specific question regarding one possible solution connected with APC to improve "something", after "optimizing" the autoloading without telling us if that worked - this all sounds like you don't properly measure and profile your application, but simply use anything you come across that promises to "optimize".