4 月 122021
 

Source: symfony doc performance

By default, the Symfony Standard Edition uses Composer’s autoloader in the autoload.php file. This autoloader is easy to use, as it will automatically find any new classes that you’ve placed in the registered directories.

Unfortunately, this comes at a cost, as the loader iterates over all configured namespaces to find a particular file, making file_exists() calls until it finally finds the file it’s looking for.

The simplest solution is to tell Composer to build an optimized “class map”, which is a big array of the locations of all the classes and it’s stored in vendor/composer/autoload_classmap.php.

The class map can be generated from the command line, and might become part of your deploy process:

composer dump-autoload --optimize --no-dev --classmap-authoritative

--optimize: Dumps every PSR-0 and PSR-4 compatible class used in your application.

--no-dev: Excludes the classes that are only needed in the development environment (e.g. tests).

--classmap-authoritative: Prevents Composer from scanning the file system for classes that are not found in the class map.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

CAPTCHA Image
Play CAPTCHA Audio
Reload Image