modernc.org/sqlite vs CGO sqlite3: Why I Run Pure Go
Go has two first-class ways to talk to SQLite:
- mattn/go-sqlite3 — the CGO driver, wraps the real SQLite C library.
- modernc.org/sqlite — a pure-Go translation of SQLite, no CGO.
Both work. I run the pure-Go one in production, and the reasons are operational, not benchmark-related. Let me be honest about the tradeoffs.
Why I chose modernc (pure Go)
- Builds anywhere, trivially. No C compiler required.
go buildjust works on Linux, Windows, and cross-compiles withGOOS/GOARCH. The CGO driver needsgccand cross-toolchains, which turn every deploy into a small adventure. - One less class of build failure. CGO adds C compilation, link flags, and platform quirks. For a single-binary service I want
go buildto be boring and repeatable. - Static binaries. No need to ship or locate the C SQLite library on the target. Copy one binary, done.
- It is real SQLite. modernc is a faithful translation of the C code, not a different engine. Compatibility is a non-issue for the features I use (WAL,
VACUUM INTO,PRAGMAs).
The honest tradeoffs
- Speed: modernc has historically been a bit slower than the CGO wrapper on some workloads. If your database is your hot path at high volume, benchmark your workload — do not trust a generic table.
- Familiarity: the CGO driver is older and more battle-tested by volume. modernc is now widely deployed too.
- Resource use: pure-Go translation can use more memory in some cases. Again — measure yours.
How I actually decided
I ran the same service with both drivers. For a typical web service doing moderate reads and writes, the difference did not move the needle. What did move it: the pure-Go driver deleted an entire class of build-and-deploy pain. A day of toolchain fighting is worth more than a few microseconds per query.
My advice: if you are on a team that already has a C toolchain and you need every drop of performance, mattn/go-sqlite3 is a fine choice. If you value boring builds and easy deployment — and most services do not need the last few percent — start with modernc.org/sqlite and measure before you switch.
Estimating the size of the database you are about to store with your driver of choice? The estimator below is driver-agnostic.
Comments (0)
No comments yet.