The problem is that classmap is NOT faster in every case!
The speed of a group card arises from the lack of the need to check the file system, if the file exists, before always doing the necessary work to download it, divulge it (operation code caches will be used here) and then execute it.
But the disadvantage of classmap is that you probably generate a huge amount of data for each individual class, interface, and attribute included in the libraries you use, without actually using it in your production code. Downloading huge arrays does not come for free - while the code does not need to be parsed again and again (the operation cache code), it must still be executed, the data structure of the array must be put into memory, filled with many lines, and then eats up some amount memory that could be used for something else.
I found two resources discussing this topic: First of all, github issue # 1529 , offering further improvements for the composer autoloader, using a bunch of symlinks to avoid scanning multiple directories.
The discussion also shows that you should try to use the best possible namespace- or classname prefix in the PSR-0 startup declaration, that is, the longest possible. You can also use more than one prefix in an ad.
Then there is a blog post related in this release that documents some xhprof tests using EZPublish 5 stock and tinker with settings, including APC Caching and class dumping.
Money Quote:
This command created a version 662KiB file vendor / composer / autoload_classmap.php containing an array that is a hash consisting of the class name as an index and the path to a file containing the class definition as a value. At the time I am writing this post, this array consists of 4168 entries. [...] Although it should give us the most efficient startup mechanism, it actually slows down (from 254.53 to 2.995). The reason is that even if the file is cached by APC, a PHP array containing a map with more than 4100 entries must be recreated with every single request.
Will the cool card be fast? Of course. Fastest in every case? Of course not - this depends on the relationship used against unused classes for each request. So even if on average your application actually uses ALL classes on the map, classmap can still be slower if you use only about 10% of the classes for each request, and youβd better optimize the autoload declarations of the libraries you use. in fact, each classname prefix must point to only one directory.
Please note that the performance gain you achieve is only about one millisecond in a single request. Your application is certainly awesome if this number is a significant increase in performance in the range of 5 to 10%. But if you really are in this performance range, blindly believing that classmap is ALWAYS faster, it probably spends a lot of unnecessary processor cycles.
If you are optimizing something: measure it! How do you know if it really gets better if you can't measure it?