Bug 1400466 - Cache the information loaded from src_comp.xdb into a structured clone buffer, r=jonco
authorSteve Fink <sfink@mozilla.com>
Fri, 08 Sep 2017 14:58:26 -0700
changeset 381723 18af2ea42a1e01e98273101fd7ed8dc0291e7a2d
parent 381722 383a2f567cebe59b0212e414b9a27d46123040bf
child 381724 6d5acbf01f1deb321693aac8330ce6e75f7f6cac
push id32536
push userkwierso@gmail.com
push dateTue, 19 Sep 2017 21:49:25 +0000
treeherdermozilla-central@a0eb21bf55e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1400466
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1400466 - Cache the information loaded from src_comp.xdb into a structured clone buffer, r=jonco Note that this requires some enhancements to the JS engine to support reading and writing structured clone data from/to files.
js/src/devtools/rootAnalysis/analyzeHeapWrites.js
js/src/devtools/rootAnalysis/callgraph.js
--- a/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
+++ b/js/src/devtools/rootAnalysis/analyzeHeapWrites.js
@@ -718,17 +718,20 @@ var removePrefix = add_trailing_slash(op
 var addPrefix = add_trailing_slash(options.add_prefix);
 
 if (options.verbose) {
     printErr(`Removing prefix ${removePrefix} from paths`);
     printErr(`Prepending ${addPrefix} to paths`);
 }
 
 print(elapsedTime() + "Loading types...");
-loadTypes('src_comp.xdb');
+if (os.getenv("TYPECACHE"))
+    loadTypesWithCache('src_comp.xdb', os.getenv("TYPECACHE"));
+else
+    loadTypes('src_comp.xdb');
 print(elapsedTime() + "Starting analysis...");
 
 var reachable = {};
 
 var xdb = xdbLibrary();
 xdb.open("src_body.xdb");
 
 var minStream = xdb.min_data_stream();
--- a/js/src/devtools/rootAnalysis/callgraph.js
+++ b/js/src/devtools/rootAnalysis/callgraph.js
@@ -211,8 +211,25 @@ function loadTypes(type_xdb_filename) {
         const data = xdb.read_entry(csu);
         const json = JSON.parse(data.readString());
         processCSU(csu.readString(), json[0]);
 
         xdb.free_string(csu);
         xdb.free_string(data);
     }
 }
+
+function loadTypesWithCache(type_xdb_filename, cache_filename) {
+    try {
+        const cacheAB = os.file.readFile(cache_filename, "binary");
+        const cb = serialize();
+        cb.clonebuffer = cacheAB.buffer;
+        const cacheData = deserialize(cb);
+        subclasses = cacheData.subclasses;
+        superclasses = cacheData.superclasses;
+        classFunctions = cacheData.classFunctions;
+    } catch (e) {
+        loadTypes(type_xdb_filename);
+        const cb = serialize({subclasses, superclasses, classFunctions});
+        os.file.writeTypedArrayToFile(cache_filename,
+                                      new Uint8Array(cb.arraybuffer));
+    }
+}