Skip to content

Pass the blob URL for preloads in WasmEMCCBenchmark. #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 8bitbench/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ function dumpFrame(vec) {

class Benchmark {
isInstantiated = false;
romBinary;

async init() {
if (isInBrowser) {
let response = await fetch(romBinary);
this.romBinary = new Int8Array(await response.arrayBuffer());
} else {
this.romBinary = new Int8Array(read(romBinary, "binary"));
}
}

async runIteration() {
if (!this.isInstantiated) {
await wasm_bindgen(Module.wasmBinary);
this.isInstantiated = true;
}

wasm_bindgen.loadRom(Module.romBinary);
wasm_bindgen.loadRom(this.romBinary);

const frameCount = 2 * 60;
for (let i = 0; i < frameCount; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions ARES-6/Babylon/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class Benchmark {
let sources = [];

const files = [
[isInBrowser ? airBlob : "./ARES-6/Babylon/air-blob.js", {}]
, [isInBrowser ? basicBlob : "./ARES-6/Babylon/basic-blob.js", {}]
, [isInBrowser ? inspectorBlob : "./ARES-6/Babylon/inspector-blob.js", {}]
, [isInBrowser ? babylonBlob : "./ARES-6/Babylon/babylon-blob.js", {sourceType: "module"}]
[airBlob, {}]
, [basicBlob, {}]
, [inspectorBlob, {}]
, [babylonBlob, {sourceType: "module"}]
];

for (let [file, options] of files) {
Expand Down
17 changes: 6 additions & 11 deletions Dart/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,14 @@ class Benchmark {
// is a map from module variable name (which will hold the resulting module
// namespace object) to relative module URL, which is resolved in the
// `preRunnerCode`, similar to this code here.
if (isInBrowser) {
// In browsers, relative imports don't work since we are not in a module.
// (`import.meta.url` is not defined.)
const pathname = location.pathname.match(/^(.*\/)(?:[^.]+(?:\.(?:[^\/]+))+)?$/)[1];
this.dart2wasmJsModule = await import(location.origin + pathname + "./Dart/build/flute.dart2wasm.mjs");
} else {

try {
this.dart2wasmJsModule = await import(jsModule);
} catch {
// In shells, relative imports require different paths, so try with and
// without the "./" prefix (e.g., JSC requires it).
try {
this.dart2wasmJsModule = await import("Dart/build/flute.dart2wasm.mjs");
} catch {
this.dart2wasmJsModule = await import("./Dart/build/flute.dart2wasm.mjs");
}
if (!isInBrowser)
this.dart2wasmJsModule = await import(jsModule.slice("./".length))
}
}

Expand Down
86 changes: 39 additions & 47 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ class Driver {
}

benchmark.updateUIAfterRun();
console.log(benchmark.name)

if (isInBrowser) {
const cache = JetStream.blobDataCache;
Expand Down Expand Up @@ -776,8 +775,8 @@ class Benchmark {

if (this.plan.preload) {
let str = "";
for (let [variableName, blobUrl] of this.preloads)
str += `const ${variableName} = "${blobUrl}";\n`;
for (let [ variableName, blobURLOrPath ] of this.preloads)
str += `const ${variableName} = "${blobURLOrPath}";\n`;
addScript(str);
}

Expand Down Expand Up @@ -994,9 +993,16 @@ class Benchmark {
if (this._resourcesPromise)
return this._resourcesPromise;

const filePromises = !isInBrowser ? this.plan.files.map((file) => fileLoader.load(file)) : [];
this.preloads = [];
this.blobs = [];

const promise = Promise.all(filePromises).then((texts) => {
if (isInBrowser) {
this._resourcesPromise = Promise.resolve();
return this._resourcesPromise;
}

const filePromises = this.plan.files.map((file) => fileLoader.load(file));
this._resourcesPromise = Promise.all(filePromises).then((texts) => {
if (isInBrowser)
return;
this.scripts = [];
Expand All @@ -1005,10 +1011,11 @@ class Benchmark {
this.scripts.push(text);
});

this.preloads = [];
this.blobs = [];
if (this.plan.preload) {
for (const prop of Object.getOwnPropertyNames(this.plan.preload))
this.preloads.push([ prop, this.plan.preload[prop] ]);
}

this._resourcesPromise = promise;
return this._resourcesPromise;
}

Expand Down Expand Up @@ -1167,7 +1174,7 @@ class AsyncBenchmark extends DefaultBenchmark {
// part of a larger project's build system or a wasm benchmark compiled from a language that doesn't compile with emcc.
class WasmEMCCBenchmark extends AsyncBenchmark {
get prerunCode() {
let str = `
return `
let verbose = false;

let globalObject = this;
Expand Down Expand Up @@ -1198,58 +1205,42 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
},
};
globalObject.Module = Module;
`;
return str;
`;
}

// FIXME: Why is this part of the runnerCode and not prerunCode?
// This is in runnerCode rather than prerunCode because prerunCode isn't currently structured to be async by default.
get runnerCode() {
let str = `function loadBlob(key, path, andThen) {`;

let str = `(async function doRunWrapper() {`
if (isInBrowser) {
str += `
var xhr = new XMLHttpRequest();
xhr.open('GET', path, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
Module[key] = new Int8Array(xhr.response);
andThen();
};
xhr.send(null);
async function getBinary(key, blobURL) {
const response = await fetch(blobURL);
Module[key] = new Int8Array(await response.arrayBuffer());
}
`;
} else {
} else
str += `
Module[key] = new Int8Array(read(path, "binary"));

Module.setStatus = null;
Module.monitorRunDependencies = null;

Promise.resolve(42).then(() => {
try {
andThen();
} catch(e) {
console.log("error running wasm:", e);
console.log(e.stack);
throw e;
// Needed because SpiderMonkey shell doesn't have a setTimeout.
Module.setStatus = null;
Module.monitorRunDependencies = null;
function getBinary(key, path) {
Module[key] = new Int8Array(read(path, "binary"));
}
})
`;
}

str += "}";

let keys = Object.keys(this.plan.preload);
for (let i = 0; i < keys.length; ++i) {
str += `loadBlob("${keys[i]}", "${this.plan.preload[keys[i]]}", async () => {\n`;
for (let [ preloadKey, blobURLOrPath ] of this.preloads) {
if (preloadKey == "wasmBinary") {
str += `await getBinary("${preloadKey}", "${blobURLOrPath}");\n`
break;
}
}

str += super.runnerCode;
for (let i = 0; i < keys.length; ++i) {
str += `})`;
}
str += `;`;

str += "\n})().catch((error) => { top.currentReject(error); });"

return str;

}
};

Expand Down Expand Up @@ -2091,7 +2082,8 @@ let BENCHMARKS = [
"./Dart/benchmark.js",
],
preload: {
wasmBinary: "./Dart/build/flute.dart2wasm.wasm"
jsModule: "./Dart/build/flute.dart2wasm.mjs",
wasmBinary: "./Dart/build/flute.dart2wasm.wasm",
},
iterations: 15,
worstCaseCount: 2,
Expand Down
2 changes: 1 addition & 1 deletion code-load/code-first-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Benchmark {

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

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

Expand Down
2 changes: 1 addition & 1 deletion code-load/code-multi-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Benchmark {
throw new Error("Expect non-empty sources");
inspectorText = request.responseText;
} else
inspectorText = readFile("./code-load/inspector-payload-minified.js");
inspectorText = readFile(inspectorPayloadBlob);

this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${inspectorText}`;
this.index = 0;
Expand Down
Loading