val players = listOf<Player>()
database.playerQueries.transaction {
players.forEach { player ->
database.playerQueries.insert(
player_number = player.number,
full_name = player.fullName
)
}
}
The sqlite.worker.js will receive a
postMessage
call for each
insert
, but I'm only able to receive around 5-10 inserts per second when running a transaction. I have a use case to insert around 100,000 entries of 0.5kB max each, which would take hours at this speed.
Has anyone experienced something similar or any ideas what might be going wrong? I wonder if
postMessage
calls are expensive on the browser.
d
Derek Ellis
06/06/2024, 1:28 PM
There's an open feature request (and an old draft PR) to introduce batching support to SQLDelight which would help a lot in a case like this (sending one big batched set of execute statements instead of thousands of individual ones)
Derek Ellis
06/06/2024, 1:29 PM
For now though, in my own project I worked around this by customizing the web worker script to do the batch insert directly in the worker
Hi Derek ! Thank you for the work done so far
Nice, I was thinking I can customize the web worker to do your own batching too or maybe also web worker pooling. Thank you for your example ! will check it out
Carlos
06/06/2024, 3:44 PM
I considered whether the
postMessage
async call could be accelerated, but finding ways to enhance its speed appears to be more complex.