sqlite / sqlite-wasm

SQLite Wasm conveniently wrapped as an ES Module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Worker reuse vs. recreating on user interaction

koramstad opened this issue · comments

Given this use case:

  • An application reads and displays data from a SQLite table upon launch.
  • Later, the user adds a new row to the table by pressing a button.

In the first step there will be created a worker for the initial data load. What is the correct approach?

  1. Terminate the worker after loading and create a new one when the user adds a new row?
  2. Don't terminate the worker after launch, instead reuse the existing worker for both loading and adding new data?
    If reusing is valid, do you need to call sqlite3InitModule for every subsequent SQLite command?

I assume that reusing the worker give better performance than creating a new one for each user interaction, but I'm not sure how this is intended to work.

You can do either, but there's no compelling reason to do (1) - it would be headache-inducingly inefficient. sqlite3InitModule() must be called exactly one time from any thread which loads the library (ideally, only a single thread per web app).

Closing this ticket, as there is no problem/bug to resolve here.