Closed Bug 986841 Opened 10 years ago Closed 10 years ago

Lazy load modules in gDevTools.jsm

Categories

(DevTools :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 31

People

(Reporter: past, Assigned: past)

References

Details

Attachments

(2 files, 1 obsolete file)

Lazy-loading Promise.jsm is straightforward since we don't use it in the top-level script, but for ProfilerController we should just require() it at the point of use as the sdk loader always loads eagerly.
This passes all tests locally.
Attachment #8395241 - Flags: review?(dcamp)
Attachment #8395241 - Flags: review?(dcamp) → review+
There is a failing test (browser_toolbox_options.js) in the try run. Working on a fix for that before landing.
Fixing that test proved harder than I expected, but totally worthwhile. The problem was that moving the ProfilerController loading out of gDevTools.jsm global scope exposed a race in the devtools loader, which would now load main.js twice in the browser_toolbox_options.js test. If main.js didn't have any side effects this might have been OK, albeit a little slower, but among other things it registers the default tools in the toolbox. The second time registerTools was called, it would unfortunately treat the default tools like add-ons, breaking the test.

To get a better understanding of the race, here is the stack trace for the first attempt to load main.js:

load@resource://gre/modules/commonjs/toolkit/loader.js:270:3
main@resource://gre/modules/commonjs/toolkit/loader.js:649:3
DevToolsLoader.prototype.main@resource://gre/modules/devtools/Loader.jsm:285:5
DevToolsLoader.prototype.setProvider@resource://gre/modules/devtools/Loader.jsm:314:7
DevToolsLoader.prototype._chooseProvider@resource://gre/modules/devtools/Loader.jsm:325:7
DevToolsLoader.prototype.provider@resource://gre/modules/devtools/Loader.jsm:242:7
DevToolsLoader.prototype.main@resource://gre/modules/devtools/Loader.jsm:285:5
@resource:///modules/devtools/gDevTools.jsm:932:1
XPCU_moduleLambda@resource://gre/modules/XPCOMUtils.jsm:226:7
XPCU_defineLazyGetter/<.get@resource://gre/modules/XPCOMUtils.jsm:177:9
gBrowserInit._delayedStartup@chrome://browser/content/browser.js:10841:5

And here is the stack from the second attempt:

load@resource://gre/modules/commonjs/toolkit/loader.js:270:3
main@resource://gre/modules/commonjs/toolkit/loader.js:649:3
DevToolsLoader.prototype.main@resource://gre/modules/devtools/Loader.jsm:285:5
@resource:///modules/devtools/gDevTools.jsm:932:1
XPCU_moduleLambda@resource://gre/modules/XPCOMUtils.jsm:226:7
XPCU_defineLazyGetter/<.get@resource://gre/modules/XPCOMUtils.jsm:177:9
gBrowserInit._delayedStartup@chrome://browser/content/browser.js:10841:5

The change I made to Loader.jsm in this patch is to bail if main() has been already called.

Try: https://tbpl.mozilla.org/?tree=Try&rev=89e7dd956b97
Attachment #8397817 - Flags: review?(dcamp)
Attachment #8395241 - Attachment is obsolete: true
Here are a bunch of cleanups and minor performance improvements that I made while digging into the aforementioned test failure. I think reasonable minds can disagree on what constitutes good taste in some of these cases and it's not necessary for fixing this bug, so feel free to dump it if you want.

Try: https://tbpl.mozilla.org/?tree=Try&rev=388424d622e1
Attachment #8398378 - Flags: review?(dcamp)
Attachment #8397817 - Flags: review?(dcamp) → review+
Attachment #8398378 - Flags: review?(dcamp) → review+
https://hg.mozilla.org/mozilla-central/rev/08873449ec1e
https://hg.mozilla.org/mozilla-central/rev/28ac5b562d9f
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 31
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: