Does Composer provide any performance over Zend Loader in ZF2

216 Views Asked by At

ZF2 is using Composer for package management and distribution. My question is that does it provide any performance boost over Zend Loader?

1

There are 1 best solutions below

1
On

Firstly, Zend\Loader is just namespace and presents multiple classes under the hood like Factories, Autoloaders, PluginLoaders, ModuleLoaders etc... So, Zend Loader !== Composer and comparing different concepts is generally wrong.

Second thing is, composer is not a "package manager" and you can use ZF2 without composer. From the documentation:

Composer is not a package manager. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it will never install anything globally. Thus, it is a dependency manager.

Primary concern of the composer is providing easy dependency management between libraries, standardising autoloading process etc.. not performance. It also prepares an autoload file for your project for all of the classes in the 3rd party libraries which installed by composer. This makes our lives better.

On the other hand, the Zend Loader namespace and related classes. This short summary from the official documentation is really straightforward:

ZF2 employs multiple autoloading strategies; as an example, you may have a class map for your most used classes, but want to use a PSR-0 style autoloader for 3rd party libraries.

A short-summary about the classes under the Zend Loader namespace:

  • ClassMapAutoloader: It's designed with performance in mind. Avoids unnecessary filesystem operations when autoloading.
  • StandardAutoloader: It's a PSR-0-compliant autoloader. Assumes a 1:1 mapping of the namespace + classname to the filesystem.
  • ModuleAutolader : A special implementation of the Zend\Loader\SplAutoloader interface, used by Zend\ModuleManager to autoload Module classes from different sources.
  • PluginClassLoader : Resolves plugin names -> to -> class names by providing a simple mechanism for aliasing plugin names to classnames for later retrieval.

So, if your main concern is filesystem-level performance, you should focus on classmap autoloading and opcode caching. There are lot of metrics which affects overall application performance and there are no silver bullet to boost performance.