Bug 1382645: Part 3 - Throw away description strings before blobbifying schema JSON. r?mixedpuppy
MozReview-Commit-ID: 8rWQQhaTRr8
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -62,19 +62,55 @@ function readJSON(url) {
resolve(JSON.parse(text));
} catch (e) {
reject(e);
}
});
});
}
+function stripDescriptions(json, stripThis = true) {
+ if (Array.isArray(json)) {
+ for (let i = 0; i < json.length; i++) {
+ if (typeof json[i] === "object" && json[i] !== null) {
+ json[i] = stripDescriptions(json[i]);
+ }
+ }
+ return json;
+ }
+
+ let result = {};
+
+ // Objects are handled much more efficiently, both in terms of memory and
+ // CPU, if they have the same shape as other objects that serve the same
+ // purpose. So, normalize the order of properties to increase the chances
+ // that the majority of schema objects wind up in large shape groups.
+ for (let key of Object.keys(json).sort()) {
+ if (stripThis && key === "description" && typeof json[key] === "string") {
+ continue;
+ }
+
+ if (typeof json[key] === "object" && json[key] !== null) {
+ result[key] = stripDescriptions(json[key], key !== "properties");
+ } else {
+ result[key] = json[key];
+ }
+ }
+
+ return result;
+}
+
async function readJSONAndBlobbify(url) {
let json = await readJSON(url);
+ // We don't actually use descriptions at runtime, and they make up about a
+ // third of the size of our structured clone data, so strip them before
+ // blobbifying.
+ json = stripDescriptions(json);
+
return new StructuredCloneHolder(json);
}
/**
* Defines a lazy getter for the given property on the given object. Any
* security wrappers are waived on the object before the property is
* defined, and the getter and setter methods are wrapped for the target
* scope.