r/sqlite • • 3d ago

How a read buffer changes the result of a 100-migration SQLite benchmark in Go

I maintain Go-Gen-Ecosystem/go-migrate. I compared v1.0.1 with golang-migrate/migrate v4.20.1 and pressly/goose v3.30.1. Each library applied the same 100 SQL migrations to a fresh SQLite database. Each migration created a table and inserted one row.

On Linux/amd64 with Go 1.26.11, the median allocated per batch across six samples was 727.8 KiB for go-migrate, 10.66 MiB for golang-migrate, and 1.14 MiB for goose. Goose made the fewest allocations at default settings, with 8,547 per batch compared with 9,420 for golang-migrate and 10,873.5 for go-migrate.

I repeated the golang-migrate benchmark with one change. Setting gm.DefaultBufferSize = 4096 at the start of its benchmark, down from the 100,000-byte default, brought its median to 892.2 KiB on these small files. All three libraries used in-memory migration sources, the same pure-Go SQLite driver, WAL, and synchronous=OFF.

To reproduce the defaults from a disposable v1.0.1 checkout, run the following. The tagged benchmark module needs -mod=mod to refresh its dependency metadata.

cd benchmarks/compare
GOWORK=off CGO_ENABLED=0 GOTOOLCHAIN=go1.26.11 go test -mod=mod -run '^$' -bench '^BenchmarkUp100_' -benchmem -count=6 .

Benchmark source · golang-migrate buffer implementation

2 Upvotes

2 comments sorted by

1

u/missinglinknz 3d ago

I’m not clear what you’re asking here exactly, is it why the db filesize differs when changing the buffer size?

What happens if you run VACUUM on these databases? I would expect the numbers to be very similar/same afterwards.

1

u/Fabulous-Cookie-6457 3d ago

I should’ve made the question clearer. I wanted to know how much the migration reader’s buffer size affects Go heap allocations when the SQL files are small. The 10.66 MiB and 892.2 KiB figures are the total bytes Go allocated while applying one batch of 100 migrations.

I tried your VACUUM suggestion on three fresh databases per buffer setting. After PRAGMA wal_checkpoint(TRUNCATE), all six database files were 424 KiB. I ran VACUUM, checkpointed again, and all six were still 424 KiB. Your intuition held for this workload. The files were already the same size before VACUUM.