Add initialize.

This commit is contained in:
Nuno Cruces
2024-05-03 12:38:40 +01:00
parent bb279cb426
commit 1e03c6c1fb
3 changed files with 19 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)