Skip to content

Commit 1e03c6c

Browse files
committed
Add initialize.
1 parent bb279cb commit 1e03c6c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

ext/stats/stats_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ func TestRegister_covariance(t *testing.T) {
180180
}
181181

182182
func Benchmark_average(b *testing.B) {
183+
sqlite3.Initialize()
184+
b.ResetTimer()
185+
183186
db, err := sqlite3.Open(":memory:")
184187
if err != nil {
185188
b.Fatal(err)
@@ -211,6 +214,9 @@ func Benchmark_average(b *testing.B) {
211214
}
212215

213216
func Benchmark_variance(b *testing.B) {
217+
sqlite3.Initialize()
218+
b.ResetTimer()
219+
214220
db, err := sqlite3.Open(":memory:")
215221
if err != nil {
216222
b.Fatal(err)

sqlite.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ var (
2828
RuntimeConfig wazero.RuntimeConfig
2929
)
3030

31+
// Initialize decodes and compiles the SQLite Wasm binary.
32+
// This is called implicitly when the first connection is openned,
33+
// but is potentially slow, so you may want to call it at a more convenient time.
34+
func Initialize() error {
35+
instance.once.Do(compileSQLite)
36+
return instance.err
37+
}
38+
3139
var instance struct {
3240
runtime wazero.Runtime
3341
compiled wazero.CompiledModule
@@ -79,9 +87,8 @@ type sqlite struct {
7987
}
8088

8189
func instantiateSQLite() (sqlt *sqlite, err error) {
82-
instance.once.Do(compileSQLite)
83-
if instance.err != nil {
84-
return nil, instance.err
90+
if err := Initialize(); err != nil {
91+
return nil, err
8592
}
8693

8794
sqlt = new(sqlite)

tests/parallel/parallel_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func TestChildProcess(t *testing.T) {
141141
}
142142

143143
func Benchmark_memdb(b *testing.B) {
144+
sqlite3.Initialize()
145+
b.ResetTimer()
146+
144147
memdb.Delete("test.db")
145148
name := "file:/test.db?vfs=memdb"
146149
testParallel(b, name, b.N)

0 commit comments

Comments
 (0)