Description
As discussed in Gitter in May 2023, with dynamic theming enabled and a large number of LayoutItem
s created. A simple fix was not apparent so I am logging the issue so it is recorded.
The lookup of the events in the event registry becomes exponentially slow. This was noticed for the destruction of a window containing many controls, compounded by the fact that some other elements in the application were not being leaked, adding to the number of event registrations.
I built a simple repl, although this is not something you would likely find in an application, but it does highlight the inefficiency of the event lookup.
Repl: https://tinyurl.com/yujzyz2t
This creates 30,000 TextFields, which is already slow to destroy (about 5 seconds), but if you bump the number up to 60,000 then it is very much slower to destroy (around 20 seconds).
The problem seems to be related to looping/manipulation of the event registry array for each event removal in this piece of code:
qooxdoo/source/class/qx/event/Manager.js
Lines 702 to 715 in 49d5fbc
My suggestion to improve was to possibly store the event listeners in a map so they could be removed by key.
Comment from @derrell at the time was:
Yeah, I can see how that would happen. There may be some O(n^2) looping going on there. The good news is that it should be refactorable in a backward-compatible fashion, I think. I'll look into it. It'll be a bit of work, so not just a 1-day project.
And then:
Unfortunately, it can't be refactored in a BC fashion. It had appeared that the data structures for maintaining all of the listeners was a purely internal matter, but unfortunately, there is a public interface for retrieving all listeners, which simply returns the existing top-level data structure. Although there are very few uses of that interface within qooxdoo, because it's public, that interface could be used in users' apps, so it can't be changed except with a major version number bump.