Follow-up to
#2501989: [meta] Page Cache Performance →
Problem/Motivation
The autoloader takes up to 500 us overall to just load and register namespaces, which is 10% of page cache response time. (5 ms)
Needless work, because lots of what makes it "slow" is work that can be done at:
a) Composer autoloader creation time
b) At container compilation / dump time
Proposed resolution
- The ClassLoader.php is already created dynamically.
Add a composer script hook for after autoloader creation to:
- Provide a ClassLoaderDrupal.php with a ClassLoaderDrupalInterface
which has all the classmap, PSR-4 namespaces, etc. already registered as variables => 1 load call, opcode cached, no run-time overhead.
- Add internal APC support that is enabled once the prefix key has been set.
- Create a faster interface to add PSR-4 namespaces with pre-compiled prefix lengths in one go => 1 call to register all namespaces of all modules
If the class loader is not of that interface => use the old way => no BC break
---
Is that providing our own solution? yes
Could it live upstream? For sure, wonder why they don't do it like that from the start ...
Lets also open an issue to solicit feedback ...
Remaining tasks
- Do it, benchmark it
User interface changes
- None
API changes
- Use a hybrid of composer class loader / APC classloader and some newly defined functions.