-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from all commits
a6bd526
8869c79
bcfccc3
510e017
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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,15 @@ class Benchmark { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (this._resourcesPromise) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._resourcesPromise; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const filePromises = !isInBrowser ? this.plan.files.map((file) => fileLoader.load(file)) : []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.preloads = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 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. Yeah, I don't fully understand it either. My guess is that various parts were edited by different people (or the same person that forgot how it worked) over time so it has lots of now dead code and/or duplicated logic. It seems like this could be greatly simplified but I'd rather do that in a follow up since this PR blocks "correct" results from the benchmark as a whole. 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. Sure, happy to have more cleanups later and land this first. 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. Filed: #86 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._resourcesPromise; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const promise = Promise.all(filePromises).then((texts) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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?
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. It does look like it. 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. Alright: let's try to remember to remove |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 +1010,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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1130,6 +1136,51 @@ class DefaultBenchmark extends Benchmark { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class AsyncBenchmark extends DefaultBenchmark { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
get prerunCode() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let str = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// FIXME: It would be nice if these were available to any benchmark not just async ones but since these functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// are async they would only work in a context where the benchmark is async anyway. Long term, we should do away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// with this class and make all benchmarks async. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isInBrowser) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str += ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function getBinary(blobURL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await fetch(blobURL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Int8Array(await response.arrayBuffer()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function getString(blobURL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await fetch(blobURL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response.text(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function dynamicImport(blobURL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return await import(blobURL); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str += ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function getBinary(path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Int8Array(read(path, "binary")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function getString(path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return read(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function dynamicImport(path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return await import(path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// In shells, relative imports require different paths, so try with and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// without the "./" prefix (e.g., JSC requires it). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return await import(path.slice("./".length)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
get runnerCode() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async function doRun() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1197,58 +1248,19 @@ class WasmEMCCBenchmark extends AsyncBenchmark { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
globalObject.Module = Module; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// FIXME: Why is this part of the runnerCode and not prerunCode? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
get runnerCode() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let str = `function loadBlob(key, path, andThen) {`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
globalObject.Module = Module; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
${super.prerunCode}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (isSpiderMonkey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str += super.runnerCode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (let i = 0; i < keys.length; ++i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str += `})`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
str += `;`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1585,7 +1597,7 @@ let BENCHMARKS = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
iterations: 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tags: ["ARES"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new DefaultBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new AsyncBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "Babylon", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
files: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"./ARES-6/Babylon/index.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1621,7 +1633,7 @@ let BENCHMARKS = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
tags: ["CDJS"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// CodeLoad | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new DefaultBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new AsyncBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "first-inspector-code-load", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
files: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"./code-load/code-first-load.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1631,7 +1643,7 @@ let BENCHMARKS = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tags: ["CodeLoad"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new DefaultBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
new AsyncBenchmark({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: "multi-inspector-code-load", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
files: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"./code-load/code-multi-load.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -2091,7 +2103,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)?