Open cjuner opened 6 years ago
1% of total response time doesn’t sound like it’s worth micro-optimizing 😉
Take a look at the flight weight pattern :)
I know the flyweight pattern, but that is still a specific optimization, which is probably not worth our time for 1%, but we'll see.
Shopware instantiates an instance of
Enlight_Event_Handler_Default
for every subscriber – even if the corresponding events are never triggered.In our default demo shops with none of our plugins enabled,
Shopware\Components\ContainerAwareEventManager->addListener
is called 125 times (2.99% of request processing time), and with 25 of our plugins, 890 times (3.30% of request processing time). That makes for a lot of unnecessary instances. The event handler's constructor takes about 1 % and 1.13 % of total request processing time, respectively.Instead, the handler could be lazily instantiated when necessary, i.e., when the event is first triggered. Until then, the constructor arguments could be cached.
https://github.com/VIISON/shopware/blob/939ed8f18cef093c20a79e4b45ca825923a30ec0/engine/Library/Enlight/Event/EventManager.php#L78