You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed some surprising latency the first time a query is run (db.Query). On my machine it takes about 400ms. Every call to db.Query afterwards returns in comparable time to other drivers.
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.
You can provide your own wazero.RuntimeConfig, by setting sqlite3.RuntimeConfig. This allows you to configure the compilation cache, choose between the compiler/interpreter, limit memory, etcβ¦) The cache can speed up first instantiation by an order of magnitude.
Slim down SQLite to reduce compilation time
If you can do away with some of the optional features, one way to improve the situation is to generate your own, slimmed down, sqlite3.wasm. You can also trade speed for size (-O3 vs -Os).
All you need is wasi-sdk, and binaryen. You can edit sqlite_opt.h to remove some of the extensions (FTS, R*Tree, GeoPoly are good candidates if you don't need them). And tweak compile options in the build.sh script. To load your own build of SQLite, you can change either the Binary or Pathvariables, instead of importing embed.
This discussion was converted from issue #31 on October 18, 2023 09:20.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
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: