pickware / shopware

Shopware Repository
http://www.shopware.com
Other
0 stars 0 forks source link

Performance(medium, 1.13%): Lazily instantiate Enlight_Event_Handler_Default (would involve SW-PR) #67

Open cjuner opened 6 years ago

cjuner commented 6 years ago

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

fixpunkt commented 6 years ago

1% of total response time doesn’t sound like it’s worth micro-optimizing 😉

windaishi commented 6 years ago

Take a look at the flight weight pattern :)

fixpunkt commented 6 years ago

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.