diff --git a/ext/stats/stats_test.go b/ext/stats/stats_test.go index f2b4280..34e19c1 100644 --- a/ext/stats/stats_test.go +++ b/ext/stats/stats_test.go @@ -180,6 +180,9 @@ func TestRegister_covariance(t *testing.T) { } func Benchmark_average(b *testing.B) { + sqlite3.Initialize() + b.ResetTimer() + db, err := sqlite3.Open(":memory:") if err != nil { b.Fatal(err) @@ -211,6 +214,9 @@ func Benchmark_average(b *testing.B) { } func Benchmark_variance(b *testing.B) { + sqlite3.Initialize() + b.ResetTimer() + db, err := sqlite3.Open(":memory:") if err != nil { b.Fatal(err) diff --git a/sqlite.go b/sqlite.go index a446ec0..593ba33 100644 --- a/sqlite.go +++ b/sqlite.go @@ -28,6 +28,14 @@ var ( RuntimeConfig wazero.RuntimeConfig ) +// Initialize decodes and compiles the SQLite Wasm binary. +// This is called implicitly when the first connection is openned, +// but is potentially slow, so you may want to call it at a more convenient time. +func Initialize() error { + instance.once.Do(compileSQLite) + return instance.err +} + var instance struct { runtime wazero.Runtime compiled wazero.CompiledModule @@ -79,9 +87,8 @@ type sqlite struct { } func instantiateSQLite() (sqlt *sqlite, err error) { - instance.once.Do(compileSQLite) - if instance.err != nil { - return nil, instance.err + if err := Initialize(); err != nil { + return nil, err } sqlt = new(sqlite) diff --git a/tests/parallel/parallel_test.go b/tests/parallel/parallel_test.go index 094c812..c285b78 100644 --- a/tests/parallel/parallel_test.go +++ b/tests/parallel/parallel_test.go @@ -141,6 +141,9 @@ func TestChildProcess(t *testing.T) { } func Benchmark_memdb(b *testing.B) { + sqlite3.Initialize() + b.ResetTimer() + memdb.Delete("test.db") name := "file:/test.db?vfs=memdb" testParallel(b, name, b.N)