Open Bug 765428 Opened 12 years ago Updated 2 years ago

Bounce events/notifications/etc through intermediary so we can load less code on startup

Categories

(Firefox :: General, defect)

defect

Tracking

()

People

(Reporter: Dolske, Unassigned)

Details

I've seen code in a number of spots that attempts to be a good citizen by lazy-loading its JSM (or _could_), but the benefit is negated because code in the module wants to observe certain notifications or events or whatever. And so the module ends up being loaded early -- by way of MyModule.init() or addObserver("blah", MyModule.observer) -- even if those notifications will commonly not fire until long after the browser has started running.

We should bounce this stuff through an intermediary, so that JSMs are only actually loaded upon first-real-use.

EG:

  defineLazyModuleGetter("SomeModule.jsm");
  defineLazyModuleGetter("BaconCore.jsm");

  function bounce(thing) {
    switch (thing.type):
      case "foo":
        SomeModule.handleFoo(thing);
        break;
      case "bar":
        SomeModule.doBar(thing);
        BaconCore.doBar(thing);
        break;
      case "burnt":
      case "crispy":
      case "soggy":
        BaconCore.cookingDone(thing);
        break;
  }

  addObserver("foo", bounce);
  addObserver("bar", bounce)
  ...
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.