Skip to content

[EventDispatcher] Performance of TraceableEventDispatcher::getNotCalledListeners() #43658

Closed
@umulmrum

Description

@umulmrum

Description
I analyzed performance issues in my project in the dev environment when I saw that TraceableEventDispatcher::getNotCalledListeners() is using up quite a bit of CPU. This is because all event listeners are instantiated which means that their dependencies are also loaded which in my case ultimately leads to the instantiation of multiple Doctrine repositories and therefore lots of annotation loading (which will also be tracked by the profiler, leading to even worse performance). When removing the call to getNotCalledListeners(), cache usage drops by 75% and wall time by 0.4s/30% which is significant even if it is "only" the dev environment. There were ~100 uncalled listeners.

So my question is if others experience the same problem in a real-world project. If yes, I suggest to improve this, e.g. by doing one of the following:

  • Avoid instantiating all listeners/subscribers, as we are only interested in names here (although I don't have an idea on how to do this).
  • Add a possibility to opt out of this feature
  • Remove the feature. I'm not sure what the rationale behind it is. The profiler already shows called events, and when wondering why a specific event listener was not called, the command debug:event-dispatcher can tell if it is registered correctly. So I suppose it might be expendable, but could of course err.

Some time ago @javiereguiluz also asked to improve performance here, see #31970, but it wasn't pursued any further.

Thanks for considering (I'm glad to help on the easier solutions if requested)!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions