Skip to content
Merged
4 changes: 2 additions & 2 deletions 8bitbench/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Benchmark {
romBinary;

async init() {
Module.wasmBinary = await getBinary(wasmBinary);
this.romBinary = await getBinary(romBinary);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
this.romBinary = await JetStream.getBinary(JetStream.preload.romBinary);
}

async runIteration() {
Expand Down
10 changes: 5 additions & 5 deletions ARES-6/Babylon/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class Benchmark {
let sources = [];

const files = [
[airBlob, {}]
, [basicBlob, {}]
, [inspectorBlob, {}]
, [babylonBlob, {sourceType: "module"}]
[JetStream.preload.airBlob, {}],
[JetStream.preload.basicBlob, {}],
[JetStream.preload.inspectorBlob, {}],
[JetStream.preload.babylonBlob, {sourceType: "module"}],
];

for (let [file, options] of files)
sources.push([file, await getString(file), options]);
sources.push([file, await JetStream.getString(file), options]);

this.sources = sources;
}
Expand Down
4 changes: 2 additions & 2 deletions Dart/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class Benchmark {
// The generated JavaScript code from dart2wasm is an ES module, which we
// can only load with a dynamic import (since this file is not a module.)

Module.wasmBinary = await getBinary(wasmBinary);
this.dart2wasmJsModule = await dynamicImport(jsModule);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
this.dart2wasmJsModule = await JetStream.dynamicImport(JetStream.preload.jsModule);
}

async runIteration() {
Expand Down
84 changes: 53 additions & 31 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,28 @@ const BenchmarkState = Object.freeze({
class Scripts {
constructor() {
this.scripts = [];
// Expose a globalThis.JetStream object to the workload. We use
// a proxy to prevent prototype access and throw on unknown properties.
this.add(`
const isInBrowser = ${isInBrowser};
const isD8 = ${isD8};
if (typeof performance.mark === 'undefined') {
performance.mark = function(name) { return { name }};
}
if (typeof performance.measure === 'undefined') {
performance.measure = function() {};
}
const throwOnAccess = (name) => new Proxy({}, {
get(target, property, receiver) {
throw new Error(name + "." + property + " is not defined.");
}
});
globalThis.JetStream = {
__proto__: throwOnAccess("JetStream"),
preload: {
__proto__: throwOnAccess("JetStream.preload"),
},
};
`);
this.add(`
performance.mark ??= function(name) { return { name }};
performance.measure ??= function() {};
`);
}


run() {
throw new Error("Subclasses need to implement this");
}
Expand All @@ -585,6 +595,13 @@ class Scripts {
throw new Error("addWithURL not supported");
}

addBrowserTest() {
this.add(`
globalThis.JetStream.isInBrowser = ${isInBrowser};
globalThis.JetStream.isD8 = ${isD8};
`);
}

addDeterministicRandom() {
this.add(`(() => {
const initialSeed = 49734321;
Expand Down Expand Up @@ -799,11 +816,13 @@ class Benchmark {

if (!!this.plan.deterministicRandom)
scripts.addDeterministicRandom()
if (!!this.plan.exposeBrowserTest)
scripts.addBrowserTest();

if (this.plan.preload) {
let preloadCode = "";
for (let [ variableName, blobURLOrPath ] of this.preloads)
preloadCode += `const ${variableName} = "${blobURLOrPath}";\n`;
preloadCode += `JetStream.preload.${variableName} = "${blobURLOrPath}";\n`;
scripts.add(preloadCode);
}

Expand Down Expand Up @@ -1259,39 +1278,39 @@ class AsyncBenchmark extends DefaultBenchmark {
// with this class and make all benchmarks async.
if (isInBrowser) {
str += `
async function getBinary(blobURL) {
JetStream.getBinary = async function(blobURL) {
const response = await fetch(blobURL);
return new Int8Array(await response.arrayBuffer());
}
};

async function getString(blobURL) {
JetStream.getString = async function(blobURL) {
const response = await fetch(blobURL);
return response.text();
}
};

async function dynamicImport(blobURL) {
JetStream.dynamicImport = async function(blobURL) {
return await import(blobURL);
}
};
`;
} else {
str += `
async function getBinary(path) {
JetStream.getBinary = async function(path) {
return new Int8Array(read(path, "binary"));
}
};

async function getString(path) {
JetStream.getString = async function(path) {
return read(path);
}
};

async function dynamicImport(path) {
JetStream.dynamicImport = async function(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;
Expand Down Expand Up @@ -1323,7 +1342,7 @@ class AsyncBenchmark extends DefaultBenchmark {
}
benchmark.validate?.(${this.iterations});
top.currentResolve(results);
}
};
doRun().catch((error) => { top.currentReject(error); });`
}
};
Expand All @@ -1342,7 +1361,7 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
console.log('Intercepted quit/abort');
};

oldPrint = globalObject.print;
const oldPrint = globalObject.print;
globalObject.print = globalObject.printErr = (...args) => {
if (verbose)
console.log('Intercepted print: ', ...args);
Expand Down Expand Up @@ -1409,7 +1428,6 @@ class WSLBenchmark extends Benchmark {

performance.measure(markLabel, markLabel);
}

top.currentResolve(results);
}`;
}
Expand Down Expand Up @@ -1469,8 +1487,7 @@ class WasmLegacyBenchmark extends Benchmark {
console.log('Intercepted quit/abort');
};

oldPrint = globalObject.print;
oldConsoleLog = globalObject.console.log;
const oldConsoleLog = globalObject.console.log;
globalObject.print = globalObject.printErr = (...args) => {
if (verbose)
oldConsoleLog('Intercepted print: ', ...args);
Expand All @@ -1483,12 +1500,12 @@ class WasmLegacyBenchmark extends Benchmark {
printErr: globalObject.print
};
globalObject.Module = Module;
`;
`;
return str;
}

get runnerCode() {
let str = `function loadBlob(key, path, andThen) {`;
let str = `JetStream.loadBlob = function(key, path, andThen) {`;

if (isInBrowser) {
str += `
Expand Down Expand Up @@ -1519,15 +1536,15 @@ class WasmLegacyBenchmark extends Benchmark {
console.log(e.stack);
throw e;
}
})
});
`;
}

str += "}";
str += "};\n";

const keys = Object.keys(this.plan.preload);
for (let i = 0; i < keys.length; ++i) {
str += `loadBlob("${keys[i]}", "${this.plan.preload[keys[i]]}", () => {\n`;
str += `JetStream.loadBlob("${keys[i]}", "${this.plan.preload[keys[i]]}", () => {\n`;
}
if (this.plan.async) {
str += `doRun().catch((e) => {
Expand Down Expand Up @@ -1845,6 +1862,8 @@ let BENCHMARKS = [
"./RexBench/UniPoker/benchmark.js",
],
deterministicRandom: true,
// FIXME: UniPoker should not access isInBrowser.
exposeBrowserTest: true,
tags: ["Default", "RexBench"],
}),
// Simple
Expand Down Expand Up @@ -2209,6 +2228,7 @@ let BENCHMARKS = [
},
async: true,
deterministicRandom: true,
exposeBrowserTest: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self / Wasm folks: once Transformers.js lands (WIP), we should get rid of this workload (so there is no need to fix this global access).

tags: ["Wasm"],
}),
new WasmLegacyBenchmark({
Expand All @@ -2229,6 +2249,7 @@ let BENCHMARKS = [
},
async: true,
deterministicRandom: true,
exposeBrowserTest: true,
tags: ["Wasm"],
}),
new WasmEMCCBenchmark({
Expand All @@ -2251,6 +2272,7 @@ let BENCHMARKS = [
files: [
"./worker/bomb.js",
],
exposeBrowserTest: true,
iterations: 80,
preload: {
rayTrace3D: "./worker/bomb-subtests/3d-raytrace.js",
Expand Down
18 changes: 9 additions & 9 deletions Kotlin-compose/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ class Benchmark {
// console.log("init");

preload = {
'skiko.wasm': await getBinary(skikoWasmBinary),
'./compose-benchmarks-benchmarks.wasm': await getBinary(composeWasmBinary),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/compose-multiplatform.png': await getBinary(inputImageCompose),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/example1_cat.jpg': await getBinary(inputImageCat),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/files/example1_compose-community-primary.png': await getBinary(inputImageComposeCommunity),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/font/jetbrainsmono_italic.ttf': await getBinary(inputFontItalic),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/font/jetbrainsmono_regular.ttf': await getBinary(inputFontRegular),
'skiko.wasm': await JetStream.getBinary(JetStream.preload.skikoWasmBinary),
'./compose-benchmarks-benchmarks.wasm': await JetStream.getBinary(JetStream.preload.composeWasmBinary),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/compose-multiplatform.png': await JetStream.getBinary(JetStream.preload.inputImageCompose),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/example1_cat.jpg': await JetStream.getBinary(JetStream.preload.inputImageCat),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/files/example1_compose-community-primary.png': await JetStream.getBinary(JetStream.preload.inputImageComposeCommunity),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/font/jetbrainsmono_italic.ttf': await JetStream.getBinary(JetStream.preload.inputFontItalic),
'./composeResources/compose_benchmarks.benchmarks.generated.resources/font/jetbrainsmono_regular.ttf': await JetStream.getBinary(JetStream.preload.inputFontRegular),
};

// We patched `skiko.mjs` to not immediately instantiate the `skiko.wasm`
// module, so that we can move the dynamic JS import here but measure
// WebAssembly compilation and instantiation as part of the first iteration.
this.skikoInstantiate = (await dynamicImport(skikoJsModule)).default;
this.mainInstantiate = (await dynamicImport(composeJsModule)).instantiate;
this.skikoInstantiate = (await JetStream.dynamicImport(JetStream.preload.skikoJsModule)).default;
this.mainInstantiate = (await JetStream.dynamicImport(JetStream.preload.composeJsModule)).instantiate;
}

async runIteration() {
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 @@ -26,7 +26,7 @@
let indirectEval = eval;
class Benchmark {
async init() {
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${await getString(inspectorPayloadBlob)}`;
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${await JetStream.getString(JetStream.preload.inspectorPayloadBlob)}`;

this.index = 0;
}
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 @@ -26,7 +26,7 @@
let indirectEval = eval;
class Benchmark {
async init() {
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${await getString(inspectorPayloadBlob)}`;
this.inspectorText = `let _____top_level_____ = ${Math.random()}; ${await JetStream.getString(JetStream.preload.inspectorPayloadBlob)}`;
this.index = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Benchmark {
sqlite3Module;

async init() {
Module.wasmBinary = await getBinary(wasmBinary);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
}

async runIteration() {
Expand Down
2 changes: 1 addition & 1 deletion wasm/HashSet/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Benchmark {
async init() {
Module.wasmBinary = await getBinary(wasmBinary);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
}

async runIteration() {
Expand Down
2 changes: 1 addition & 1 deletion wasm/TSF/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class Benchmark {
async init() {
Module.wasmBinary = await getBinary(wasmBinary);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
}

async runIteration() {
Expand Down
2 changes: 1 addition & 1 deletion wasm/argon2/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const saltLength = 12;

class Benchmark {
async init() {
Module.wasmBinary = await getBinary(wasmBinary);
Module.wasmBinary = await JetStream.getBinary(JetStream.preload.wasmBinary);
}

async runIteration() {
Expand Down
Loading
Loading