Bug 1364768: Part 7 - Synchronously load the initial set of API scripts at startup. r?aswan
Loading these scripts synchronously has some advantages, but it has the
disadvangate of significantly delaying the loading of schema files, and
therefore initialization of the first extension.
Fortunately, with the advent of
bug 1359653, we can load these from the
startup cache with little to no additional additional main thread overhead.
MozReview-Commit-ID: BrICSgJW0F2
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -90,41 +90,34 @@ let apiManager = new class extends Schem
}
// Loads all the ext-*.js scripts currently registered.
lazyInit() {
if (this.initialized) {
return this.initialized;
}
- let scripts = [];
for (let [/* name */, value] of XPCOMUtils.enumerateCategoryEntries(CATEGORY_EXTENSION_SCRIPTS)) {
- scripts.push(value);
+ Services.scriptloader.loadSubScript(value, this.global);
}
- let promise = Promise.all(scripts.map(url => ChromeUtils.compileScript(url))).then(scripts => {
- for (let script of scripts) {
- script.executeInGlobal(this.global);
+ // Load order matters here. The base manifest defines types which are
+ // extended by other schemas, so needs to be loaded first.
+ let promise = Schemas.load(BASE_SCHEMA).then(() => {
+ let promises = [];
+ for (let [/* name */, url] of XPCOMUtils.enumerateCategoryEntries(CATEGORY_EXTENSION_SCHEMAS)) {
+ promises.push(Schemas.load(url));
}
-
- // Load order matters here. The base manifest defines types which are
- // extended by other schemas, so needs to be loaded first.
- return Schemas.load(BASE_SCHEMA).then(() => {
- let promises = [];
- for (let [/* name */, url] of XPCOMUtils.enumerateCategoryEntries(CATEGORY_EXTENSION_SCHEMAS)) {
- promises.push(Schemas.load(url));
- }
- for (let url of this.schemaURLs) {
- promises.push(Schemas.load(url));
- }
- for (let url of schemaURLs) {
- promises.push(Schemas.load(url));
- }
- return Promise.all(promises);
- });
+ for (let url of this.schemaURLs) {
+ promises.push(Schemas.load(url));
+ }
+ for (let url of schemaURLs) {
+ promises.push(Schemas.load(url));
+ }
+ return Promise.all(promises);
});
/* eslint-disable mozilla/balanced-listeners */
Services.mm.addMessageListener("Extension:GetTabAndWindowId", this);
/* eslint-enable mozilla/balanced-listeners */
this.initialized = promise;
return this.initialized;