Skip to content

Commit 21aa2dc

Browse files
committed
Pass the blob URL for preloads in WasmEMCCBenchmark.
Right now we pass the original path when loading preloads for WasmEMCCBenchmark. This means we might skip the cache and fetch the content from the network again. We don't want to do this because it means the OS might spin down the CPU, which can punish running faster. I also moved this logic to the `prerunCode` rather than adding it to the `runnerCode` since logically that makes more sense. As a drive by change, this patch has the preloads tuples contain the path for cli runs. This means we no longer have to duplicate the preload paths into the benchmark.js file. Additionally, remove a console.log of the test that just finished which broke the dumpJSONResults option for the CLIs.
1 parent 539ab94 commit 21aa2dc

File tree

4 files changed

+44
-64
lines changed

4 files changed

+44
-64
lines changed

ARES-6/Babylon/benchmark.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class Benchmark {
3131
let sources = [];
3232

3333
const files = [
34-
[isInBrowser ? airBlob : "./ARES-6/Babylon/air-blob.js", {}]
35-
, [isInBrowser ? basicBlob : "./ARES-6/Babylon/basic-blob.js", {}]
36-
, [isInBrowser ? inspectorBlob : "./ARES-6/Babylon/inspector-blob.js", {}]
37-
, [isInBrowser ? babylonBlob : "./ARES-6/Babylon/babylon-blob.js", {sourceType: "module"}]
34+
[airBlob, {}]
35+
, [basicBlob, {}]
36+
, [inspectorBlob, {}]
37+
, [babylonBlob, {sourceType: "module"}]
3838
];
3939

4040
for (let [file, options] of files) {

JetStreamDriver.js

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ class Driver {
281281
}
282282

283283
benchmark.updateUIAfterRun();
284-
console.log(benchmark.name)
285284

286285
if (isInBrowser) {
287286
const cache = JetStream.blobDataCache;
@@ -776,8 +775,8 @@ class Benchmark {
776775

777776
if (this.plan.preload) {
778777
let str = "";
779-
for (let [variableName, blobUrl] of this.preloads)
780-
str += `const ${variableName} = "${blobUrl}";\n`;
778+
for (let [ variableName, blobUrlOrPath ] of this.preloads)
779+
str += `const ${variableName} = "${blobUrlOrPath}";\n`;
781780
addScript(str);
782781
}
783782

@@ -994,9 +993,16 @@ class Benchmark {
994993
if (this._resourcesPromise)
995994
return this._resourcesPromise;
996995

997-
const filePromises = !isInBrowser ? this.plan.files.map((file) => fileLoader.load(file)) : [];
996+
this.preloads = [];
997+
this.blobs = [];
998+
999+
if (isInBrowser) {
1000+
this._resourcesPromise = Promise.resolve();
1001+
return this._resourcesPromise;
1002+
}
9981003

999-
const promise = Promise.all(filePromises).then((texts) => {
1004+
const filePromises = this.plan.files.map((file) => fileLoader.load(file));
1005+
this._resourcesPromise = Promise.all(filePromises).then((texts) => {
10001006
if (isInBrowser)
10011007
return;
10021008
this.scripts = [];
@@ -1005,10 +1011,11 @@ class Benchmark {
10051011
this.scripts.push(text);
10061012
});
10071013

1008-
this.preloads = [];
1009-
this.blobs = [];
1014+
if (this.plan.preload) {
1015+
for (const prop of Object.getOwnPropertyNames(this.plan.preload))
1016+
this.preloads.push([ prop, this.plan.preload[prop] ]);
1017+
}
10101018

1011-
this._resourcesPromise = promise;
10121019
return this._resourcesPromise;
10131020
}
10141021

@@ -1199,57 +1206,30 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
11991206
};
12001207
globalObject.Module = Module;
12011208
`;
1202-
return str;
1203-
}
1204-
1205-
// FIXME: Why is this part of the runnerCode and not prerunCode?
1206-
get runnerCode() {
1207-
let str = `function loadBlob(key, path, andThen) {`;
1208-
1209-
if (isInBrowser) {
1210-
str += `
1211-
var xhr = new XMLHttpRequest();
1212-
xhr.open('GET', path, true);
1213-
xhr.responseType = 'arraybuffer';
1214-
xhr.onload = function() {
1215-
Module[key] = new Int8Array(xhr.response);
1216-
andThen();
1217-
};
1218-
xhr.send(null);
1219-
`;
1220-
} else {
1221-
str += `
1222-
Module[key] = new Int8Array(read(path, "binary"));
1223-
1224-
Module.setStatus = null;
1225-
Module.monitorRunDependencies = null;
1226-
1227-
Promise.resolve(42).then(() => {
1228-
try {
1229-
andThen();
1230-
} catch(e) {
1231-
console.log("error running wasm:", e);
1232-
console.log(e.stack);
1233-
throw e;
1234-
}
1235-
})
1236-
`;
1237-
}
1238-
1239-
str += "}";
1240-
1241-
let keys = Object.keys(this.plan.preload);
1242-
for (let i = 0; i < keys.length; ++i) {
1243-
str += `loadBlob("${keys[i]}", "${this.plan.preload[keys[i]]}", async () => {\n`;
1244-
}
1245-
1246-
str += super.runnerCode;
1247-
for (let i = 0; i < keys.length; ++i) {
1248-
str += `})`;
1249-
}
1250-
str += `;`;
12511209

1252-
return str;
1210+
if (isInBrowser) {
1211+
str += `
1212+
function getBinary(key, blobUrl) {
1213+
var xhr = new XMLHttpRequest();
1214+
xhr.open('GET', blobUrl, false);
1215+
xhr.responseType = 'arraybuffer';
1216+
xhr.send(null);
1217+
Module[key] = new Int8Array(xhr.response);
1218+
}
1219+
`;
1220+
} else
1221+
str += `
1222+
Module.setStatus = null;
1223+
Module.monitorRunDependencies = null;
1224+
function getBinary(key, path) {
1225+
Module[key] = new Int8Array(read(path, "binary"));
1226+
}
1227+
`;
1228+
1229+
for (let [ preloadKey, blobUrlOrPath ] of this.preloads)
1230+
str += `getBinary("${preloadKey}", "${blobUrlOrPath}");\n`
1231+
1232+
return str;
12531233
}
12541234
};
12551235

code-load/code-first-load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Benchmark {
3737

3838
inspectorText = request.responseText;
3939
} else
40-
inspectorText = readFile("./code-load/inspector-payload-minified.js");
40+
inspectorText = readFile(inspectorPayloadBlob);
4141

4242
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${inspectorText}`;
4343

code-load/code-multi-load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Benchmark {
3636
throw new Error("Expect non-empty sources");
3737
inspectorText = request.responseText;
3838
} else
39-
inspectorText = readFile("./code-load/inspector-payload-minified.js");
39+
inspectorText = readFile(inspectorPayloadBlob);
4040

4141
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${inspectorText}`;
4242
this.index = 0;

0 commit comments

Comments
 (0)