wp-rocket
wp-rocket copied to clipboard
[R&D] Defer subscriber instantiation to when the first event it is subscribed to is received.
Context
Reduce the plugin CPU usage: https://wp-media.slack.com/archives/CUT7FLHF1/p1704447166535709
Expected behavior When loading the plugin, subscribers should not be instantiated straight away. Subscriptions to their events should be made with a lazy load approach so that the subscriber and its dependencies are loaded only when the first event is received. As a result, the loading sequence of the plugin should be reduced, as seen through XDebug. It would be nice to be able to selectively apply this approach to some subscribers so that we lazy load the biggest/less used ones.
R&D ideas
- Build a proxy to the actual subscriber OR
- Register an anonymous function as a callback to the events, returning
container->get('the_subscriber')->the_actual_callback
(should work since subscribers are declared withshare
and notadd
in the service providers). OR any other approach.
How to check results with XDebug https://wp-media.slack.com/archives/CUT7FLHF1/p1704728991213049