Slow latency on first query? #32
-
Love the idea behind this! I've noticed some surprising latency the first time a query is run ( It's like there is some kind of expensive one time setup that occurs at that point. I don't know if this is expected behavior or not. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is a good question that I'd like to keep highlighted here, rather than in a closed issue. |
Beta Was this translation helpful? Give feedback.
-
Yes, this is expected behaviour, though maybe it should be documented better. We embed a Wasm version of SQLite. This needs to be compiled to machine code on the first instantiation: Lines 70 to 71 in 58c5009 wazero (our WASM runtime) is quite fast at compiling, but the WASM file is also quite big (1.4Mb), hence the slowdown. There are 3 ways to mitigate this cost:
Compile at a more appropriate timeThis should do the job: if err := sqlite3.Initialize(); err != nil {
log.Fatal(err)
} You can also do this in a background goroutine. Cache the compilation resultYou can provide your own Slim down SQLite to reduce compilation timeIf you can do away with some of the optional features, one way to improve the situation is to generate your own, slimmed down, All you need is |
Beta Was this translation helpful? Give feedback.
Yes, this is expected behaviour, though maybe it should be documented better.
We embed a Wasm version of SQLite. This needs to be compiled to machine code on the first instantiation:
go-sqlite3/sqlite.go
Lines 70 to 71 in 58c5009
wazero (our WASM runtime) is quite fast at compiling, but the WASM file is also quite big (1.4Mb), hence the slowdown.
There are 3 ways to mitigate this cost:
Compile at a more appropriate time
This should do the job: