Skip to content

Commit 8d5353a

Browse files
committed
explicitly set VFS to use, ensure browser and shell runner produce same result, format
1 parent 279da8d commit 8d5353a

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

sqlite3/runner.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,67 @@
1-
// Copyright 2023 the V8 project authors. All rights reserved.
1+
// Copyright 2024 the V8 project authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

55
const inJetStreamRunner = typeof globalThis.benchmarkTime !== "undefined";
66
if (inJetStreamRunner) {
77
// Use JetStream interception of `print()`, see `WasmBenchmark.prerunCode()`.
8-
globalThis.console.debug = globalThis.console.warn = globalThis.console.error = globalThis.console.log = print;
8+
globalThis.console.debug =
9+
globalThis.console.warn =
10+
globalThis.console.error =
11+
globalThis.console.log =
12+
print;
913
} else {
1014
load("polyfills.js");
1115

1216
// Exports `sqlite3InitModule()` and contains the main code.
1317
load("build/jswasm/speedtest1.js");
1418

1519
// Load Wasm binary from disk.
16-
globalThis.Module = { wasmBinary: read("build/jswasm/speedtest1.wasm", "binary") };
20+
globalThis.Module = {
21+
wasmBinary: read("build/jswasm/speedtest1.wasm", "binary"),
22+
};
1723
}
1824

19-
// Heavily simplified from inline JavaScript in `speedtest1.html`.
25+
// Make sure we never initialize OPFS by removing one of it's APIs (see
26+
// `installOpfsVfs` in the generated JavaScript code of sqlite).
27+
// We never want to use it anyway (see VFS config below) and this way we don't
28+
// waste cycles on the browser runner to initialize it.
29+
delete globalThis.FileSystemHandle;
30+
31+
// Simplified from inline JavaScript in `speedtest1.html`.
2032
function runTests(sqlite3Module) {
21-
const wasm = sqlite3Module.wasm;
22-
// Required for `scopedAllocMainArgv()`.
23-
wasm.scopedAllocPush();
24-
// This should match the browser version at `speedtest1.html`.
33+
// Configure the VFS to use.
34+
// Don't use OPFS, WASMFS (which is on top of OPFS), or kvvfs, since they all
35+
// use persistent browser storage (localStorage or OPFS), which is not
36+
// available in JavaScript shells.
37+
// Also don't use memfs, since that crashes with a NULL function pointer.
38+
// Instead, make the default VFS explicit.
39+
const capi = sqlite3Module.capi
40+
console.log("Available SQLite VFS:", capi.sqlite3_js_vfs_list());
41+
const vfs = "unix";
42+
console.log("Using VFS:", vfs);
43+
const pVfs = capi.sqlite3_vfs_find(vfs);
44+
if (!pVfs) {
45+
console.error("Error: Unknown VFS:", vfs);
46+
return;
47+
}
48+
49+
// These arguments should match the upstream browser runner `speedtest1.html`.
2550
let argv = [
51+
"speedtest1",
2652
"--singlethread",
2753
//"--nomutex",
2854
//"--nosync",
2955
//"--memdb", // note that memdb trumps the filename arg
3056
"--nomemstat",
3157
"--big-transactions" /*important for tests 410 and 510!*/,
3258
"--size", "20", // To speedup, default is 100 (and takes about 4s).
59+
"--vfs", vfs, // See VFS comment above.
3360
];
34-
print("Calling main with argv:\n ", argv);
61+
62+
console.log("Calling main with argv:", argv);
63+
const wasm = sqlite3Module.wasm;
64+
wasm.scopedAllocPush(); // Required for `scopedAllocMainArgv()`.
3565
wasm.xCall("wasm_main", argv.length, wasm.scopedAllocMainArgv(argv));
3666
wasm.scopedAllocPop();
3767
}
@@ -43,7 +73,7 @@ async function doRun() {
4373

4474
start = benchmarkTime();
4575
runTests(sqliteModule);
46-
reportRunTime(benchmarkTime() - start)
76+
reportRunTime(benchmarkTime() - start);
4777
}
4878
if (!inJetStreamRunner) {
4979
sqlite3InitModule(Module).then(runTests);

0 commit comments

Comments
 (0)