-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what happens in
or something. |
||
this.dart2wasmJsModule = await import(jsModule.slice("./".length)) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -281,7 +281,6 @@ class Driver { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
benchmark.updateUIAfterRun(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(benchmark.name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isInBrowser) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const cache = JetStream.blobDataCache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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 = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT, |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const promise = Promise.all(filePromises).then((texts) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isInBrowser) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this._resourcesPromise = Promise.resolve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't fully understood the (somewhat intertwined, complex) preload, resource loading code. At a high-level, why do we just early return here having added anything to |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._resourcesPromise; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const filePromises = this.plan.files.map((file) => fileLoader.load(file)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get this in conjunction with Lines 199 to 225 in 6947a46
if (!isInBrowser) Promise.resolve(readFile(url)) . In other words, isn't this whole remaining code of fileLoader superfluous?
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this._resourcesPromise = Promise.all(filePromises).then((texts) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isInBrowser) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.scripts = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between Line 1138 in 6947a46
Could one unify the two, or move this code into async init() ?
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I said above, this |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get rid of this special casing of just the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this is essentially shared code with the
getBinary
function inWasmEMCCBenchmark
below, just that there it's only used for initializing theModule["wasmBinary"] = getBinary(...)
and here it's for an arbitrary (non-Wasm) file, that happens to be the emulator ROM, right?Can we unify this, ideally also with the mechansim for preloading blogs of JavaScript line items (ARES-6/Babylon below)?