Splitting this out from #2368275: EntityRouteEnhancer and ContentFormControllerSubscriber implicitly depend on too many services which will reduce the dependency chain of the entity route enhancer. Opening this issue to address the issue more systemically, see the discussion there for more background.
Issue summary
Route enhancers are implemented as event listeners and all of them are run on every request. This is unnecessary since each route enhancer will only apply to a subset of routes. This is problematic as all dependencies together with their chain will have to be initialized, even they aren't used
Proposed solution
Proposed by znerol:
Wrap the existing route enhancers / route filters with a lazy version of them. The lazy version has stored for each route which enhancers/filters apply
to them. Based upon that, you just have to initialize the route filters/enhancers which are actually needed.
Api change
A new interface got introduced:
\Drupal\Core\Routing\Enhancer\RouteEnhancerInterface
and\Drupal\Core\Routing\RouteFilterInterface
Based upon that services can specify themselves as + - { name: lazy_route_filter }
which will let them not be loaded on every request.
Beta phase evaluation
Issue priority | Critical because of performance |
---|---|
Prioritized changes | The main goal of this issue is performance. |
Disruption | Not disruptive, existing code with continue to work as exactly the same as before |