Skip to content

Commit cbce1b8

Browse files
committed
Move sqlite Wasm benchmark to first, worst, average scoring
Drive-by: remove unused polyfills, update sqlite source distribution, rebuild
1 parent 21b9a95 commit cbce1b8

File tree

7 files changed

+120
-124
lines changed

7 files changed

+120
-124
lines changed

JetStreamDriver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ const BENCHMARKS = [
20102010
worstCaseCount: 2,
20112011
testGroup: WasmGroup
20122012
}),
2013-
new WasmLegacyBenchmark({
2013+
new WasmEMCCBenchmark({
20142014
name: "sqlite3-wasm",
20152015
files: [
20162016
"./sqlite3/polyfills.js",
@@ -2020,7 +2020,8 @@ const BENCHMARKS = [
20202020
preload: {
20212021
wasmBinary: "./sqlite3/build/jswasm/speedtest1.wasm"
20222022
},
2023-
benchmarkClass: WasmLegacyBenchmark,
2023+
iterations: 15,
2024+
worstCaseCount: 2,
20242025
testGroup: WasmGroup
20252026
}),
20262027
new WasmLegacyBenchmark({

sqlite3/benchmark.js

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,68 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
const inJetStreamRunner = typeof globalThis.benchmarkTime !== "undefined";
6-
if (!inJetStreamRunner) {
7-
load("polyfills.js");
5+
// Since a small portion of the setup of code of SQLite is run immediately
6+
// when loading it, some polyfills are split out of this file and loaded first.
87

9-
// Exports `sqlite3InitModule()` and contains the main code.
10-
load("build/jswasm/speedtest1.js");
11-
12-
// Load Wasm binary from disk.
13-
globalThis.Module = {
14-
wasmBinary: read("build/jswasm/speedtest1.wasm", "binary"),
15-
};
16-
}
8+
// Use JetStream functions instead of `console.log` and friends.
9+
globalThis.sqlite3ApiConfig = {
10+
log: print,
11+
debug: print,
12+
warn: print,
13+
error: print,
14+
};
1715

1816
// Make sure we never initialize OPFS by removing one of it's APIs (see
1917
// `installOpfsVfs` in the generated JavaScript code of sqlite).
2018
// We never want to use it anyway (see VFS config below) and this way we don't
2119
// waste cycles on the browser runner to initialize it.
2220
delete globalThis.FileSystemHandle;
2321

24-
// Simplified from inline JavaScript in `speedtest1.html`.
25-
function runTests(sqlite3Module) {
26-
// Configure the VFS to use.
27-
// Don't use OPFS, WASMFS (which is on top of OPFS), or kvvfs, since they all
28-
// use persistent browser storage (localStorage or OPFS), which is not
29-
// available in JavaScript shells.
30-
// Also don't use memfs, since that crashes with a NULL function pointer.
31-
// Instead, make the default VFS explicit.
32-
const capi = sqlite3Module.capi
33-
console.log("Available SQLite VFS:", capi.sqlite3_js_vfs_list());
34-
const vfs = "unix";
35-
console.log("Using VFS:", vfs);
36-
const pVfs = capi.sqlite3_vfs_find(vfs);
37-
if (!pVfs) {
38-
console.error("Error: Unknown VFS:", vfs);
39-
return;
40-
}
22+
class Benchmark {
23+
sqlite3Module;
4124

42-
// These arguments should match the upstream browser runner `speedtest1.html`.
43-
let argv = [
44-
"speedtest1",
45-
"--singlethread",
46-
//"--nomutex",
47-
//"--nosync",
48-
//"--memdb", // note that memdb trumps the filename arg
49-
"--nomemstat",
50-
"--big-transactions" /*important for tests 410 and 510!*/,
51-
"--size", "20", // To speedup, default is 100 (and takes about 4s).
52-
"--vfs", vfs, // See VFS comment above.
53-
];
25+
async runIteration() {
26+
if (!this.sqlite3Module) {
27+
// Defined in the generated SQLite JavaScript code.
28+
// Different in details but seemingly related/inspired by Emscripten code.
29+
this.sqlite3Module = await sqlite3InitModule(Module);
30+
}
5431

55-
console.log("Calling main with argv:", argv);
56-
const wasm = sqlite3Module.wasm;
57-
wasm.scopedAllocPush(); // Required for `scopedAllocMainArgv()`.
58-
wasm.xCall("wasm_main", argv.length, wasm.scopedAllocMainArgv(argv));
59-
wasm.scopedAllocPop();
60-
}
32+
// The following is simplified from inline JavaScript in `speedtest1.html`.
33+
34+
// Configure the VFS to use.
35+
// Don't use OPFS, WASMFS (which is on top of OPFS), or kvvfs, since they
36+
// all use persistent browser storage (localStorage or OPFS), which is not
37+
// available in JavaScript shells.
38+
// Also don't use memfs, since that crashes with a NULL function pointer.
39+
// Instead, make the default VFS explicit.
40+
const capi = this.sqlite3Module.capi
41+
print("Available SQLite VFS:", capi.sqlite3_js_vfs_list());
42+
const vfs = "unix";
43+
print("Using VFS:", vfs);
44+
const pVfs = capi.sqlite3_vfs_find(vfs);
45+
if (!pVfs) {
46+
throw new Error("Unknown VFS:", vfs);
47+
}
6148

62-
async function doRun() {
63-
let start = benchmarkTime();
64-
const sqliteModule = await sqlite3InitModule(Module);
65-
reportCompileTime(benchmarkTime() - start);
49+
// These arguments should match the upstream browser runner in
50+
// `speedtest1.html`, except for the --size parameter.
51+
let argv = [
52+
"speedtest1",
53+
"--singlethread",
54+
//"--nomutex",
55+
//"--nosync",
56+
//"--memdb", // note that memdb trumps the filename arg
57+
"--nomemstat",
58+
"--big-transactions" /*important for tests 410 and 510!*/,
59+
"--size", "10", // To speedup, default is 100 (and takes about 4s).
60+
"--vfs", vfs, // See VFS comment above.
61+
];
6662

67-
start = benchmarkTime();
68-
runTests(sqliteModule);
69-
reportRunTime(benchmarkTime() - start);
70-
}
71-
if (!inJetStreamRunner) {
72-
sqlite3InitModule(Module).then(runTests);
63+
print("Calling main with argv:", argv);
64+
const wasm = this.sqlite3Module.wasm;
65+
wasm.scopedAllocPush(); // Required for `scopedAllocMainArgv()`.
66+
wasm.xCall("wasm_main", argv.length, wasm.scopedAllocMainArgv(argv));
67+
wasm.scopedAllocPop();
68+
}
7369
}

sqlite3/build.log

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Built on 2024-12-05 14:24:19+01:00
1+
Built on 2025-01-21T15:10:24Z
22

33
Toolchain versions
4-
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.71 (4171ae200b77a6c266b0e1ebb507d61d1ade3501)
4+
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.73 (ac676d5e437525d15df5fd46bc2c208ec6d376a3)
55
wasm-strip 1.0.34
66

7-
Getting sources from https://sqlite.org/2024/sqlite-src-3470100.zip
7+
Getting sources from https://sqlite.org/2025/sqlite-src-3480000.zip
88

99
Building...
1010
Copying files from sqlite-src-*/ext/wasm/ into build/

sqlite3/build.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash
22

3-
set -e
4-
set -o pipefail
3+
set -eo pipefail
54

65
# Cleanup old files.
7-
rm sqlite-src-*.zip
6+
rm -f sqlite-src-*.zip
87
rm -rf sqlite-src-*/
98
rm -rf build/
109

@@ -17,7 +16,7 @@ emcc --version | head -n1 | tee -a "$BUILD_LOG"
1716
echo -e "wasm-strip $(wasm-strip --version)\n" | tee -a "$BUILD_LOG"
1817

1918
# Check https://sqlite.org/download.html and update the source link, if needed.
20-
SQLITE_SRC_URL="https://sqlite.org/2024/sqlite-src-3470100.zip"
19+
SQLITE_SRC_URL="https://sqlite.org/2025/sqlite-src-3480000.zip"
2120
echo -e "Getting sources from $SQLITE_SRC_URL\n" | tee -a "$BUILD_LOG"
2221
SQLITE_SRC_FILE="$(basename $SQLITE_SRC_URL)"
2322
curl -o "$SQLITE_SRC_FILE" $SQLITE_SRC_URL

0 commit comments

Comments
 (0)