Problem/Motivation
Reflecting every class and method defined in a Drupal install is both a performance and memory nightmare.
Steps to reproduce
Proposed resolution
There are two solutions:
- Move nikic/php-parser to runtime, use it on classes, it has a constant expression evaluate feature and attributes are using such. This is going to a lot of fun especially cross class constants. For performance, this solution would use #3486503: Add a core FileCache implementation that is database-backed. The drawback is an awful lot of effort would need to go into this.
- Swallow the bitter pill and ship core/modules with attributes dumped. The drawback and it's a major one is development becomes harder as something needs to re-dump attributes on file change, manually or automatically. Of course many projects have went down this route, most famously perhaps sass --watch and cargo watch and they lived to tell the tale. https://github.com/olvlvl/composer-attribute-collector/ is a good start but it likely would need to changed to fork for every class or project at least otherwise the memory issue is back.
Remaining tasks
Decide whether to do #1 or #2 and how.