The problem with PSR-0 and PSR-4 (and the class-map) its implementation doesn't consider the optimization. The implementation is lacking at best.
However, the idea behind the class-map works.
I created a library that works generating a class-map. However, this class-map is way simpler yet it's optimized.
https://github.com/eftec/autoloadone
The map is reduced even for a big project, it groups the same classes of the same namespace if they are contained in the same folder. If not, then it's not a problem they are also included. Also, if the class lack of namespace, two classes in a file, the file is outside of the scope, it's not a problem, it tracks all of them. You could even exclude some folders or namespace.
For example, in a big project
Number of Classes: 898
Number of Namespaces: 62
Number of Maps: 117
Number of PHP Files: 1693
Number of PHP Autorun: 0
Number of conflict: 1
Ratio map: 6.91% (less is better. 100% means one map/one file)
Map size: 12.9 kbytes (less is better, it's an estimate of the memory used by the map)
So, for a project with 898 classes, the map uses only 12.9kb.
And what's the difference in performance:
- it doesn't need to scan a folder (for example if the file doesn't exist).
- it doesn't verify if the file doesn't exist.
- it's only a single file. So, the overhead is a single include, not 3 for
Composer's autoload includes (for each call) the next files:
- autoload.php
- composer/ClassLoader.php (it depends in the configuration)
- composer/autoload_real.php
- composer/autoload_namespaces.php
- composer/autoload_psr4.php
- composer/autoload_classmap.php (89kb)
or it runs the files:
- autoload.php
- composer/ClassLoader.php (it depends in the configuration)
- composer/autoload_static.php (107kb)
While Opcache does marvel but we are still including, at least, two includes (instead of one), plus one of them is huge and it is still an overhead, and it is still per call.
So, which is faster. It depends on the project but I checked that usually PSR-0 is faster. However, the difference is dim, both are slow. :-P