1
- // Copyright 2023 the V8 project authors. All rights reserved.
1
+ // Copyright 2024 the V8 project authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
5
const inJetStreamRunner = typeof globalThis . benchmarkTime !== "undefined" ;
6
6
if ( inJetStreamRunner ) {
7
7
// 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 ;
9
13
} else {
10
14
load ( "polyfills.js" ) ;
11
15
12
16
// Exports `sqlite3InitModule()` and contains the main code.
13
17
load ( "build/jswasm/speedtest1.js" ) ;
14
18
15
19
// 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
+ } ;
17
23
}
18
24
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`.
20
32
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`.
25
50
let argv = [
51
+ "speedtest1" ,
26
52
"--singlethread" ,
27
53
//"--nomutex",
28
54
//"--nosync",
29
55
//"--memdb", // note that memdb trumps the filename arg
30
56
"--nomemstat" ,
31
57
"--big-transactions" /*important for tests 410 and 510!*/ ,
32
58
"--size" , "20" , // To speedup, default is 100 (and takes about 4s).
59
+ "--vfs" , vfs , // See VFS comment above.
33
60
] ;
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()`.
35
65
wasm . xCall ( "wasm_main" , argv . length , wasm . scopedAllocMainArgv ( argv ) ) ;
36
66
wasm . scopedAllocPop ( ) ;
37
67
}
@@ -43,7 +73,7 @@ async function doRun() {
43
73
44
74
start = benchmarkTime ( ) ;
45
75
runTests ( sqliteModule ) ;
46
- reportRunTime ( benchmarkTime ( ) - start )
76
+ reportRunTime ( benchmarkTime ( ) - start ) ;
47
77
}
48
78
if ( ! inJetStreamRunner ) {
49
79
sqlite3InitModule ( Module ) . then ( runTests ) ;
0 commit comments