10

I am working on a relatively large ExtJS MVC application with around >40 Controllers, >100 Stores, >100 Models and so on. I don't follow the possible MVC way strict so I implemented a lazy controller initialization which initialize the controller first when it is required and so the stores. I also don't register any view within any controller, but that simply cause I don't need to.

Now it comes that forms (opened within a Ext.window.Window) take around 1-2 second until they shown up while the same form within a rather small project pops up immediately. So the form (layout) can not be the problem here what brought me to the events. But I don't really know how would be the best way or is there already a good tutorial how to do this. I guess it would be nice to profile this, to see how long the whole pipe takes (not only the EventPipe itself).

Event structure:

Most of the events get registered via control() of the responsible controller. All other events are at most registered with { single: true }. The windows get closed and reinstantiated when reused.

sra
  • 23,820
  • 7
  • 55
  • 89
  • 1
    Btw, do you clean up your controllers correctly? If you destroy a controller the listeners on the EventBus don't get cleaned up by the framework. Sorry, not an answer to your question, but related. – mistaecko Sep 15 '12 at 16:55
  • @mistaecko Thank you for that additional info! This is really good to know! But currently I don't recycle the controllers once they are initialized so this should take no effect. As far as know from my looks at the sourcecode the controllers get stored within a internal collection of the ApplicationController. But I guess it is not done with simple profiling of event dispatchings – sra Sep 15 '12 at 17:55
  • 1
    If you ever decide to clean up your controllers, then check out my answer on how to destroy controllers here: http://stackoverflow.com/questions/12330846/how-to-delete-controller-extjs/12344788#12344788 – mistaecko Sep 16 '12 at 02:43

1 Answers1

6

I'm afraid but ExtJS doesn't provide any event profiling. It use custom event system.

Here is how I see the solution of this issue.

There are Ext.util.Event class that provides functionality to dispatching and handling any event used in the framework and Ext.app.EventBus that provide single point to dispatch all framework events (fireEvent is just wrapper for Ext.app.EventBus.dispatch method).

Classes are private so I recommend to see its source code.

You can override these classes to see how much it takes from calling Ext.app.EventBus.dispatch method and calling event listener within Ext.util.Event.fire method smth like that (EventProfiler is supposed to be your own class)

Ext.app.EventBus

dispatch: function (/* event name or Ext.util.Event */event, /* Target class */ target, args) {
    //start timing
    var start = new Date();

    /* ... */

    for (i = 0, ln = events.length; i < ln; i++) {
        event = events[i];
        // Fire the event!
        if (event.fire.apply(event, Array.prototype.slice.call(args, 1)) === false) {
            return false;
        }
        // start event profiling
        // here we are sure that event is dispatched and it's instance of Ext.util.Event
        EventProfiler.startProfile(event, /* time passed from dispath method started */new Date() - start);
    }

    /* rest of dispatch method call */
}

Ext.util.Event

fire: function () {
    /* ... */
    if (listener.o) {
        args.push(listener.o);
    }

    EventProfiler.endProfile(this);

    if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
        return (me.firing = false);
    }

    /* ... */       

}
maxmalov
  • 510
  • 2
  • 12
  • That was what I had in mind to. But I hadn't looked that detailed into the sourcecode, just a quick glance at the EventBus. I will test this on monday. Good answer anyway +1 – sra Sep 15 '12 at 11:21
  • I am very interested in your findings. Maybe you could post your results here on SO or on the Sencha forums! – mistaecko Sep 16 '12 at 02:45
  • I made first quick tests prototyping the responsible functions and it looks good so far. I have no time yet to keep working on a profiler but I will come back to this topic as soon as found some time. And yes @mistaecko I will post the result here. – sra Sep 20 '12 at 06:35