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 understand that for common-case efficiency bun:sqlite exposes a synchronous interface. But for high-latency storage providers (like database on NFS, or a custom distributed VFS like mvsqlite) an asynchronous interface would help in preventing the main thread from getting blocked on I/O.
What is the feature you are proposing to solve the problem?
Add an asynchronous SQLite interface backed by a thread pool, alongside the current synchronous interface.
What alternatives have you considered?
No response
Reacted by Viktor Urbanas, lin72h, Skywalker512, Roberto von Schoettler, Spencer Sellers, Hobbs, Kamil Tomšík, Wavering Ana, Dan Goodman, Tobias Lins and 22 more
Reacted by lin72h, Hobbs, Tobias Lins and joseferben
This is not just about performance, but also about availability. If there's slow SQL query, it will block main thread, right? And no other requests can be handled (sockets will be accepted but not handled before sqlite will return)
Maybe if there was at least .step() method, then the impact of this would be much smaller?
Based on a very quick read of Write-Ahead Log, it seems like that solves what I thought was not possible with sqlite - parallel queries. Not 100% sure.
Reacted by Tobias Lins, lin72h, Pierre, Nulo and CrushedAsian255
I have a server-side application running that needs to concurrently service 100s of different SQLite databases (one per user).
Bun's SQLite implementation certainly is fast, however at this degree of concurrency, the sheer amount of synchronous I/O grinds my event loop to a crawl.
My "solution" is to (ab)-use Bun's new worker threads:
I spin up N worker threads
Each thread has an LRU which maps database path to database
Queries {sql : string, params : { ... }, databasePath: string } are passed as messages round-robin to worker threads
The worker that receives the message grabs the database from the LRU
Runs the query and posts the result back to the main thread.
Based on a very quick read of Write-Ahead Log, it seems like that solves what I thought was not possible with sqlite - parallel queries. Not 100% sure.
I believe this would only be true if your queries are run across multiple Bun processes/threads. If the queries all happen within the same process/thread then the synchronous nature of the API should mean the WAL confers no benefit to you.
Activity
Jarred-Sumner commentedon Aug 5, 2022
Probably will be necessary eventually but async will ~always be slower outside of this usecase
Electroid commentedon Nov 3, 2022
It might make sense to expose an
AsyncDatabase, where all the functions are async.cztomsik commentedon Dec 7, 2023
This is not just about performance, but also about availability. If there's slow SQL query, it will block main thread, right? And no other requests can be handled (sockets will be accepted but not handled before sqlite will return)
Maybe if there was at least
.step()method, then the impact of this would be much smaller?small-angel commentedon Feb 5, 2024
Based on a very quick read of Write-Ahead Log, it seems like that solves what I thought was not possible with sqlite - parallel queries. Not 100% sure.
tlonny commentedon Oct 27, 2025
I have a server-side application running that needs to concurrently service 100s of different SQLite databases (one per user).
Bun's SQLite implementation certainly is fast, however at this degree of concurrency, the sheer amount of synchronous I/O grinds my event loop to a crawl.
My "solution" is to (ab)-use Bun's new worker threads:
{sql : string, params : { ... }, databasePath: string }are passed as messages round-robin to worker threadstlonny commentedon Oct 27, 2025
I believe this would only be true if your queries are run across multiple Bun processes/threads. If the queries all happen within the same process/thread then the synchronous nature of the API should mean the WAL confers no benefit to you.
isaachinman commentedon Oct 27, 2025
@Jarred-Sumner Also requesting an optional async API. There are genuine use cases for it, and this issue has been open for years.
Well aware it'll be slower and look worse on benchmarks, but as an opt-in it would be really useful.
theshadow27 commentedon Jan 16, 2026
Another use case is DB scrubs, consistency checking, etc. When the DB gets to ~mb and you're checking relationships between json objects.
ninjaasmoke commentedon Jul 25, 2026
Opened #34863
AsyncDatabase, as @Electroid suggested.@Jarred-Sumner you were right that it's slower per query: 10k sequential reads are 8.84 ms sync vs 179.66 ms async.
The win is availability, which is what @cztomsik was pointing at.
One ~400 ms query while 100
/pings arrive:DatabaseAsyncDatabaseOpt-in, own
sqlite3*, sync path untouched.bun:sqlite(173) andnode:sqlite(112) pass unchanged.CI hasn't run (fork PR), Buildkite build is blocked. Could someone unblock it?
Send a tool call's thought signature back to Gemini, and show errors …