Fix between benchmark network requests for Dart-flute's JS Module. In that process I also had to change how 8bitbench loads the rom it's going to use.

This commit is contained in:
Keith Miller 2025-06-26 16:23:28 -04:00
parent 8869c7954b
commit bcfccc33d6
Failed to extract signature
3 changed files with 26 additions and 15 deletions

View file

@ -1,4 +1,5 @@
// Copyright 2025 the V8 project authors. All rights reserved.
// Copyright 2025 Apple Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -34,6 +35,16 @@ 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) {
@ -41,7 +52,7 @@ class Benchmark {
this.isInstantiated = true;
}
wasm_bindgen.loadRom(Module.romBinary);
wasm_bindgen.loadRom(this.romBinary);
const frameCount = 2 * 60;
for (let i = 0; i < frameCount; ++i) {

View file

@ -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))
}
}

View file

@ -1228,8 +1228,12 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
}
`;
for (let [ preloadKey, blobURLOrPath ] of this.preloads)
str += `await getBinary("${preloadKey}", "${blobURLOrPath}");\n`
for (let [ preloadKey, blobURLOrPath ] of this.preloads) {
if (preloadKey == "wasmBinary") {
str += `await getBinary("${preloadKey}", "${blobURLOrPath}");\n`
break;
}
}
str += super.runnerCode;
@ -2078,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,