use better-sqlite3 as sqlite database driver (or provide the option)
See original GitHub issueProblem
sqlite is a synchronous access database, e.g. only one connection can read from the database at a time. So the async api that sqlite3 provides actually does more harm than good. This is better explained by the creator of better-sqlite3 than I can:
- node-sqlite3 uses asynchronous APIs for tasks that are either CPU-bound or serialized. That’s not only bad design, but it wastes tons of resources. It also causes mutex thrashing which has devastating effects on performance.
- node-sqlite3 exposes low-level (C language) memory management functions. better-sqlite3 does it the JavaScript way, allowing the garbage collector to worry about memory management.
- better-sqlite3 is simpler to use, and it provides nice utilities for some operations that are very difficult or impossible in node-sqlite3.
- better-sqlite3 is much faster than node-sqlite3 in most cases, and just as fast in all other cases. (also here: https://github.com/JoshuaWise/better-sqlite3/issues/262)
I am building a performance-heavy local web app. My gut feeling when building apps like this is that handwritten sql statements will always be more performant than ORM generated statements. Given that, I feel that picking prisma for sqlite has an extra hurdle to get over, that the driver under the hood isnt as performant as it could be.
Suggested solution
If support for this driver feels worthwhile, there are two options. Either provide a driver
option in the schema datasource:
datasource sqlite {
provider = "sqlite"
driver = "better-sqlite3"
url = "file:./dev.db"
}
or just replace the internal sqlite3 database with better-sqlite3.
Alternatives
Additional context
If sqlite3 was chosen because it is backed by mapbox and therefore has a better chance of being long-lived, it appears that sqlite3 is also maintained by a single person: https://kewde.github.io/sqlite
If this looks interesting to the contributors, I am willing to open a pr with some guidance!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (7 by maintainers)
We use the Rust driver for SQLite under the hood: https://github.com/rusqlite/rusqlite . We interface with it via our quaint library: https://github.com/prisma/quaint
We can’t consume any Node.js library as a driver so for this feature request to be feasiable, there should be a Rust counter part and I also assume Rust SQLite might already be faster than better-sqlite3 so that would need some investigation.
Prisma client is powered by a Rust engine under the hood. You can find the source code of that here: https://github.com/prisma/prisma-engines. We are not using any node js driver under the hood.
https://github.com/prisma/prisma/issues/12785