Open Zyava opened 11 years ago
This will result in a huge class map containing all classes, right? But in most cases only a remarkably smaller portion of all classes (especially in lib) are actually being used. The resulting classmap might be unnecessary big eating up memory and making accessing it slower.
What would be the benefit of a pre-generated classmap?
Benefits are evident:
Regarding memory, we can try to hash class name with crc32 and use SplFixedArray (http://php.net/manual/en/class.splfixedarray.php) or judy arrays (http://www.php.net/manual/en/class.judy.php). Memory footprint of judy array is very small, especially if we go with crc32 and of Judy::INT_TO_MIXED mode (crc32($fileName) => $path). I believe it would be around 5MB, but some benchmarks are needed of course.
Becuase there is no serialization support in judy arrays at the moment it can be used only with opcache. In non-opcache mode we can try to utilize crc32 + SplFixedArray (if memory footprint isn't too big) or fallback to current implementation.
However I'm not sure there is any sense to consider non-opcache mode at all. All modern websites use opcache. And since judy arrays need additional extension, why not install ZendOptimizer or APC too?
See FS classmap generator from m2: https://github.com/magento/magento2/blob/master/dev/tools/classmap/fs_generator.php. The idea is to not cache on the fly but just generate class path cache one time after the deploy. I don't think it is common when new classes are created on production after deploy.