PDA

View Full Version : Ext.Event static listeners[] slows down listeners removal



gbulfon
31 Aug 2009, 7:05 AM
Hello,
I write this following a previous post about "slow closing windowed forms".
I have found the key point to my problem:
- Event has a static vector containing all the listeners to elements/event-types/methods
- On window close (or panel removal) every registered listener is removed
- Searching for this listeners is done sequentially on the static vector (through an Ext.each)
- This approach cause a complete scan of the vector for each element/event-type/method being removed
- When the application is complex enough, you may end up having thousands of registered elements/event-types/methods, so opening a dialog over this application, will add new listeners that, on window close, will take a long time to be removed.

I found a post on the Ext2 forum of a guy that suggested a different approach: by implementing the listeners vector as a hash by element id, having the value as a vector of registered event-types/methods. This would obviously reduce the weight on removeListener, reducing scan to just the event-types/methods for that element id.

I would not like nor to modify the ext-base nor to extend it in my code to overwrite its implementation (something I will be forced to do if there is no other solution).
Do you suggest me somethind different?

Thanks a lot,
Gabriele.

Condor
31 Aug 2009, 7:19 AM
That is a rather big change in ext-base, which I don't see happening anytime soon.

I do however have a problem with the current _getCacheIndex method: It doesn't stop after finding the index!

function _getCacheIndex(el, eventName, fn) {
var index = -1;
Ext.each(listeners, function (v,i) {
if(v && v[FN] == fn && v[EL] == el && v[TYPE] == eventName) {
index = i;
return false;
}
});
return index;
}

gbulfon
31 Aug 2009, 7:25 AM
Hi, thanx for the response ;)
Anyway, I don't understand why it's such a big change.
I see it as an internal implementation that requires just few Event methods to be changed.
Am I wrong?
G.

Condor
31 Aug 2009, 7:26 AM
Yes, but it's the foundation that Ext is build on. Changing it would require VERY rigorous testing.

gbulfon
31 Aug 2009, 7:32 AM
...it's a real pity this problem has not been taken into consideration during the 3.x rewriting.
The solution was already been posted by a user for 2.x.
...even though I don't know if it had side effects...

So, I have no other chance but extend Ext.Event rewriting the specific methods?
Will I be able to rewrite the static listener vector?
Can you suggest the correct method to do this?

Thanks a lot,
Gabriele.

Condor
31 Aug 2009, 7:34 AM
You can't override Ext.lib.Event, because the code is largely private. You can only replace it entirely.

ps. When you are making your changes, also remember that not every element will necessarily have an id.

gbulfon
31 Aug 2009, 7:51 AM
Ok, I tried this, that in my case was very useful: just changed the _getCahceIndex into this


function _getCacheIndex(el, eventName, fn) {
/* var index = -1;
Ext.each(listeners, function (v,i) {
if(v && v[FN] == fn && v[EL] == el && v[TYPE] == eventName) {
index = i;
}
});
return index;*/
var index = -1;
var len=listeners.length;
for(var i=len-1;i>=0;--i) {
var v=listeners[i];
if(v && v[FN] == fn && v[EL] == el && v[TYPE] == eventName) {
index = i;
break;
}
}
return index;
}


Because the opened window forms are usually the last ones, scanning the vector backwards and exiting on match, makes it work great :)
...but I had to modify your code...and I'll have to put it inside the non-debug source too...