Hi Internals,
I would like to propose the addition of a new mechanism of autoloading
classes - a classmap that will be consulted prior to checking the
spl_autoload_register'd callbacks.https://wiki.php.net/rfc/autoload_classmap
Mark Randall
marandall@php.net
Hi Mark. A few questions.
-
As the stated reason for this RFC is performance, have you any benchmarks to show how much we'd win by using an engine-space lookup rather than user-space lookup?
-
"Setting the classmap can be performed once per request." That's not consistent with the way the autoload functions are implemented. I know some frameworks do funky dynamic registration on the Composer autoloader to handle plugin code. Allowing them to do the same with a classmap seems beneficial, to the extent that an internal class map is beneficial. Even if it cannot be added to per se, "fetch, modify, and overwrite" seems like a necessary feature, especially if there is a function to retrieve the current map. What other purpose would that function have?
-
The lower-casing of class names feels weird to me. Why? Given that most filesystems are case sensitive, that seems like an odd requirement and the RFC doesn't include an explanation of why that's beneficial.
--Larry Garfield
- As the stated reason for this RFC is performance, have you any benchmarks to show how much we'd win by using an engine-space lookup rather than user-space lookup?
Performance benefit is unfortunately quite small, my tests suggest it is
in the region of 3 to 5% vs invoking a userland function an equivilent
number of times and looking up in a classmap. It's ever so slightly
higher if comparing against something doing a lowercase on each one.
If that's enough to justify it passing an RFC is left to the voters. The
intent is for a free micro optimization at framework level that most
users would never see.
- The lower-casing of class names feels weird to me. Why? Given that most filesystems are case sensitive, that seems like an odd requirement and the RFC doesn't include an explanation of why that's beneficial.
The filesystem is case sensitive, but the class names are not, and are
handled as lowercase at engine level. new Foo() is the same - new foo()
as far as lookups.
Requiring lowercase names means that the lookup will perform the same
regardless of which case is used in the code. Doing otherwise would
require either an exact case match (which is not how PHP operates), or
forcing the list to lowercase at the call to autoload_set_classmap,
which would harm performance when it's perfectly reasonable to expect a
static lowercase map to be given.
It is important to note that only the array key is lowercase, the value,
the path name, IS case sensitive.
Mark Randall