Skip to content

Commit 1aac3ca

Browse files
authored
Merge pull request #710 from wado-lang/claude/setup-sqlite-benchmark-g0Us7
Add SQLite parser benchmark comparing Gale-generated vs sqlparser-rs
2 parents 72d7fc2 + deb190d commit 1aac3ca

File tree

9 files changed

+576
-0
lines changed

9 files changed

+576
-0
lines changed

.github/scripts/run_wado_benchmarks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ for (const opt of OPT_LEVELS) {
4848

4949
output = runBench('benchmark/json_catalog/json_catalog.wado', opt);
5050
benchmarks.push({ name: `json/catalog (${label})`, unit: 'ms', value: parseMs(output) });
51+
52+
output = runBench('benchmark/sqlite_parse/sqlite_parse.wado', opt, ['--dir', '.::.']);
53+
benchmarks.push({ name: `sqlite_parse (${label})`, unit: 'ms', value: parseMs(output) });
5154
}
5255

5356
process.stdout.write(JSON.stringify(benchmarks, null, 2) + '\n');

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
*/fts_zig
99
*/fts_zig.o
1010
*/target/
11+
Cargo.lock

benchmark/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ mise run benchmark-json-canada
8181
mise run benchmark-json-catalog
8282
```
8383

84+
### SQLite Parsing (`sqlite_parse/`)
85+
86+
Parses 81 realistic SQLite statements (13KB of SQL) using a parser generated by Gale from the ANTLR4 `SQLite.g4` grammar. Compares Gale's auto-generated recursive descent parser (Wado, compiled to Wasm) against Rust's `sqlparser-rs` (hand-written recursive descent, native).
87+
88+
- **Use case**: Parser generator output performance, tokenizer + parser throughput
89+
- **Operations**: Lexing (tokenization), recursive descent parsing, CST construction
90+
- **Data**: 81 statements — DDL (CREATE TABLE/INDEX/VIEW), DML (INSERT/UPDATE/DELETE), SELECTs with JOINs, CTEs, subqueries, CASE expressions, UNION/INTERSECT, built-in functions
91+
- **Comparison**: Gale-generated parser (Wado/Wasm) vs `sqlparser-rs` (native Rust)
92+
93+
```bash
94+
mise run benchmark-sqlite-parse
95+
```
96+
8497
## Prerequisites
8598

8699
To run all benchmarks, ensure you have the following tools installed:
@@ -105,6 +118,7 @@ mise run benchmark-fts
105118
mise run benchmark-json-twitter
106119
mise run benchmark-json-canada
107120
mise run benchmark-json-catalog
121+
mise run benchmark-sqlite-parse
108122
```
109123

110124
## Recent Results
@@ -207,6 +221,15 @@ Both implementations parse 55,563 coordinate points from GeoJSON.
207221

208222
Both implementations parse 184 events and 243 performances from CITM catalog data. Rust uses `BTreeMap` (ordered map) to match Wado's `TreeMap`.
209223

224+
### SQLite Parsing (13KB, 81 statements x 100 iterations)
225+
226+
| Runtime | Time (ms) | Per iteration (us) | Relative |
227+
| -------------------------------------- | --------- | ------------------ | -------- |
228+
| Rust (sqlparser-rs, native) | 182 | 1,825 | 1.00x |
229+
| **Wado** (Gale-generated parser, Wasm) | 4,284 | 42,836 | 23.46x |
230+
231+
Both implementations parse 81 SQL statements per iteration. The Gale parser is auto-generated from ANTLR4's `SQLite.g4` grammar; `sqlparser-rs` is a hand-tuned native Rust parser.
232+
210233
## Profiling Wado Programs
211234

212235
`wado run --profile <mode>` enables runtime profiling via wasmtime's profiling infrastructure.
@@ -308,6 +331,7 @@ samply record wado run --profile perfmap benchmark/count_prime/count_prime.wado
308331
- Zig benchmarks use `-OReleaseFast`
309332
- JSON benchmarks compare Wado's `core:json` (pure Wado, Wasm) against Rust's `serde_json` (native). Rust uses `BTreeMap` for map fields to match Wado's `TreeMap`
310333
- JSON test data from [nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark)
334+
- SQLite parser benchmark compares Gale-generated parser (Wado, Wasm) against Rust's `sqlparser-rs` (native hand-written recursive descent)
311335

312336
## File Structure
313337

@@ -321,5 +345,6 @@ benchmark/
321345
├── json_twitter/{json_twitter.wado,serde_json.rs,twitter.json}
322346
├── mandelbrot/mandelbrot.{wado,c,js}
323347
├── sieve/sieve.{wado,c,js}
348+
├── sqlite_parse/{sqlite_parse.wado,sqlparser_rs.rs,queries.sql}
324349
└── zlib/{zlib_bench.wado,zlib_rs.rs,zlib_c.c}
325350
```

benchmark/mise.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ echo "=== Wado ==="
209209
cargo run --release --manifest-path ../wado-cli/Cargo.toml --quiet -- run -O2 --dir ..::. json_catalog/json_catalog.wado
210210
"""
211211

212+
[tasks.sqlite-parse]
213+
description = "Run sqlite-parse benchmark (Gale parser vs sqlparser-rs)"
214+
run = """
215+
#!/usr/bin/env bash
216+
set -e
217+
218+
echo "=== Compiling Rust sqlparser-rs benchmark ==="
219+
cargo build --release --manifest-path sqlite_parse/Cargo.toml --quiet
220+
221+
echo "=== Rust sqlparser-rs ==="
222+
./sqlite_parse/target/release/sqlite_parse_bench
223+
224+
echo "=== Wado (Gale) ==="
225+
cargo run --release --manifest-path ../wado-cli/Cargo.toml --quiet -- run -O2 --dir ..::. sqlite_parse/sqlite_parse.wado
226+
"""
227+
212228
[tasks.all]
213229
description = "Run all benchmarks serially"
214230
run = """
@@ -222,6 +238,7 @@ MISE_JOBS=1 mise run fts
222238
MISE_JOBS=1 mise run json-twitter
223239
MISE_JOBS=1 mise run json-canada
224240
MISE_JOBS=1 mise run json-catalog
241+
MISE_JOBS=1 mise run sqlite-parse
225242
"""
226243

227244
[tasks.clean]

benchmark/sqlite_parse/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
3+
[package]
4+
name = "sqlite-parse-bench"
5+
version = "0.1.0"
6+
edition = "2024"
7+
publish = false
8+
9+
[[bin]]
10+
name = "sqlite_parse_bench"
11+
path = "sqlparser_rs.rs"
12+
13+
[dependencies]
14+
sqlparser = { version = "0.55", features = ["visitor"] }

0 commit comments

Comments
 (0)