Skip to content

Slow latency on first query? #32

Answered by ncruces
JonathanHope asked this question in Q&A
Discussion options

You must be logged in to vote

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

func instantiateSQLite() (sqlt *sqlite, err error) {
instance.once.Do(compileSQLite)

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:

  1. compile at a more appropriate time
  2. cache the compilation result
  3. slim down SQLite to reduce compilation time

Compile at a more appropriate time

This should do the job:

if err := sqlite3.Initialize(); e…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ncruces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #31 on October 18, 2023 09:20.