Skip to content

Commit bcfccc3

Browse files
committed
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.
1 parent 8869c79 commit bcfccc3

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

8bitbench/benchmark.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2025 the V8 project authors. All rights reserved.
2+
// Copyright 2025 Apple Inc. All rights reserved.
23
// Use of this source code is governed by a BSD-style license that can be
34
// found in the LICENSE file.
45

@@ -34,14 +35,24 @@ function dumpFrame(vec) {
3435

3536
class Benchmark {
3637
isInstantiated = false;
38+
romBinary;
39+
40+
async init() {
41+
if (isInBrowser) {
42+
let response = await fetch(romBinary);
43+
this.romBinary = new Int8Array(await response.arrayBuffer());
44+
} else {
45+
this.romBinary = new Int8Array(read(romBinary, "binary"));
46+
}
47+
}
3748

3849
async runIteration() {
3950
if (!this.isInstantiated) {
4051
await wasm_bindgen(Module.wasmBinary);
4152
this.isInstantiated = true;
4253
}
4354

44-
wasm_bindgen.loadRom(Module.romBinary);
55+
wasm_bindgen.loadRom(this.romBinary);
4556

4657
const frameCount = 2 * 60;
4758
for (let i = 0; i < frameCount; ++i) {

Dart/benchmark.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,14 @@ class Benchmark {
266266
// is a map from module variable name (which will hold the resulting module
267267
// namespace object) to relative module URL, which is resolved in the
268268
// `preRunnerCode`, similar to this code here.
269-
if (isInBrowser) {
270-
// In browsers, relative imports don't work since we are not in a module.
271-
// (`import.meta.url` is not defined.)
272-
const pathname = location.pathname.match(/^(.*\/)(?:[^.]+(?:\.(?:[^\/]+))+)?$/)[1];
273-
this.dart2wasmJsModule = await import(location.origin + pathname + "./Dart/build/flute.dart2wasm.mjs");
274-
} else {
269+
270+
try {
271+
this.dart2wasmJsModule = await import(jsModule);
272+
} catch {
275273
// In shells, relative imports require different paths, so try with and
276274
// without the "./" prefix (e.g., JSC requires it).
277-
try {
278-
this.dart2wasmJsModule = await import("Dart/build/flute.dart2wasm.mjs");
279-
} catch {
280-
this.dart2wasmJsModule = await import("./Dart/build/flute.dart2wasm.mjs");
281-
}
275+
if (!isInBrowser)
276+
this.dart2wasmJsModule = await import(jsModule.slice("./".length))
282277
}
283278
}
284279

JetStreamDriver.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,12 @@ class WasmEMCCBenchmark extends AsyncBenchmark {
12281228
}
12291229
`;
12301230

1231-
for (let [ preloadKey, blobURLOrPath ] of this.preloads)
1232-
str += `await getBinary("${preloadKey}", "${blobURLOrPath}");\n`
1231+
for (let [ preloadKey, blobURLOrPath ] of this.preloads) {
1232+
if (preloadKey == "wasmBinary") {
1233+
str += `await getBinary("${preloadKey}", "${blobURLOrPath}");\n`
1234+
break;
1235+
}
1236+
}
12331237

12341238
str += super.runnerCode;
12351239

@@ -2078,7 +2082,8 @@ let BENCHMARKS = [
20782082
"./Dart/benchmark.js",
20792083
],
20802084
preload: {
2081-
wasmBinary: "./Dart/build/flute.dart2wasm.wasm"
2085+
jsModule: "./Dart/build/flute.dart2wasm.mjs",
2086+
wasmBinary: "./Dart/build/flute.dart2wasm.wasm",
20822087
},
20832088
iterations: 15,
20842089
worstCaseCount: 2,

0 commit comments

Comments
 (0)