Bug 1364768: Part 7 - Synchronously load the initial set of API scripts at startup. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 14 May 2017 16:14:55 -0700
changeset 577576 e3af12f73427dd5e047883ace508094f63dca6b7
parent 577575 129da39e7c39b031eaa16b605a558e49754ebe1d
child 628527 afaaaeb5a3b443859e249a657578e197c699984f
push id58718
push usermaglione.k@gmail.com
push dateSun, 14 May 2017 23:25:47 +0000
reviewersaswan
bugs1364768, 1359653
milestone55.0a1
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
toolkit/components/extensions/ExtensionParent.jsm
--- 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;