r/sqlite • u/web3samy • Oct 05 '26
Pure GO SQLite-compatible database. 75× C SQLite & 200× Turso.
I've been building musql (pronounced "muscle"), a SQLite-compatible database written from scratch.
Repo: https://github.com/samyfodil/musql
It has a `database/sql` driver that registers as `sqlite`, so switching from another SQLite driver is usually just changing the import line. It uses its own storage format (`.musq`), with columns stored contiguously and an append-only delta for writes. `musql-convert` converts existing SQLite files in and out, in both directions.
SQL compiles to VDBE bytecode, the same design as C SQLite. A JIT turns hot paths into native code on amd64 and arm64 (Linux, macOS and Windows).
There's also `musqld`, a server that speaks Turso's Hrana protocol. `@libsql/client` and `libsql-client-go` connect unchanged, and there's a 5 MB Docker image. Replication supports CRDT or leader mode; you supply the network.
For performance, these are 100k-row read workloads, averaged over an amd64 and an arm64 machine:
filtered `count(*)`: ~75x faster than C SQLite, ~210x faster than Turso
sum over a filter: ~8x faster than C SQLite
grouped aggregate: ~2.3x faster; `ORDER BY ... LIMIT`: ~2.4x faster
It also runs Doom. The same VM that runs SQL runs unmodified doomgeneric, compiled C -> LLVM IR -> VDBE bytecode. On an Intel i9 it gets ~38 fps on the bytecode interpreter and ~96 fps with the JIT. The idea came from Turso's demo. You can try it with:
It's early. I'd appreciate feedback on the API and the Hrana server, or a bug report if your SQL breaks. A failing query helps a lot.
1
u/web3samy Oct 06 '26
Reran it at 10x the table to check, same machine, 100k vs 1M rows:
- count(*) WHERE v > ?: C goes 6.8 ms → 71.6 ms (it scales with the rows), musql goes 104x → 140x faster
- sum over a filter: 8x → 10x
- GROUP BY / ORDER BY LIMIT: 3x at both sizes
If the cgo crossing were driving these numbers, they'd shrink as the table grows, because the crossing count per query stays fixed while the work grows 10x. They didn't. C's time is the scan.
Where you're right is the per-call stuff. Point lookups are ~25 µs per query, measured from Go through database/sql, so that's mostly driver overhead rather than SQLite itself. musql is slower than C there anyway (1.1-1.6x). I'll make the README say "measured from Go via database/sql" so the claim is scoped properly. Thanks for pushing on it.
The harness is in the repo (compat-harness/bench_columnar_vs_c_test.go), and BENCH_ROWS=1000000 reproduces this.
https://github.com/samyfodil/musql/issues/1