March 03, 2025
Rust to TypeScript Update: Boosting Prisma ORM Performance
The Query Compiler project upgrades Prisma ORM by swapping out the traditional Rust engine for a leaner solution built on a WASM module and TypeScript. This change boosts query performance and cuts the bundle size by 85–90%, while also improving compatibility with a variety of web frameworks and bundlers. As Prisma ORM heads toward version 7, developers can expect a smoother, more efficient experience.
Breaking performance barriers
To quickly recap, the Query Compiler project is our push to replace the Prisma query engine, written in Rust, with a lean WASM module and supplemental TypeScript code. With this move we expected faster queries and a smaller footprint and now we’ve run benchmarks to prove it.
Since our last update, our team has been heads down on this project. With Prisma ORM 6.4 we have reached an important milestone: a working proof-of-concept of the Query Compiler. This alpha version contains the needed APIs to run comprehensive benchmarks against our existing Prisma Client implementations. You can check out the code and full benchmark results in our ORM benchmarks repo.
A new architecture for Prisma Client
The architecture of the Prisma Client with a Query Compiler builds on our current architecture for Driver Adapters. In the current Driver Adapters implementation, Prisma Client queries are sent from TypeScript, through the query engine, driver adapter, and database driver and then finally arrive at your database.
With the Query Compiler, Prisma Client queries are instead first translated to an internal query plan and then passed back to the client to be sent to your database via the same driver adapter and database driver setup. If you’re using the driverAdapters
preview feature today, the new implementation will work very similarly.
This shift isn’t just about modernization; it’s about making Prisma ORM faster and simpler. We are confident that the new architecture will have significantly less “gotchas”, allowing for developers to integrate Prisma ORM in their stack without worrying about compatibilities.
Key Benefits of the New Architecture
Faster performance
The main driver behind this project is that while Rust is very quick, the cost of serializing data between Rust and TypeScript is very high. This cost negates any benefit gained from having our Query Engine in Rust and we have seen significant improvements with the new architecture.
No more extra binaries
By removing our dependency on a Rust binary, we have eliminated a whole class of issues that resulted from managing an extra file in your development pipeline. From the simple problem of strict networks being unable to install the binary, to complex issues around making sure that your production and development environments have the correct file, none of these issues are present in the Query Compiler project.
On top of that, the removal of the binary means that if your environment can run JavaScript, it can run Prisma ORM. We expect to see the largest pain points of environments like AWS Lambda or Cloudflare Workers to be resolved. Your Prisma Client will now fit naturally into your application stack.
Significantly reduced bundle size
Our initial testing shows that while the Rust-based Prisma query engine clocks in roughly 14 MB (7 MB gzipped), the new Query Compiler is just about 1.6 MB (600 KB gzipped) representing an 85-90% reduction in size on average. Less disk space means your deployments are quicker and your apps can be deployed to more platforms easily.
Benchmark Results
The numbers speak for themselves. When compared to the existing Rust query engine, the new Query Compiler (QC) architecture results in performance gains that get progressively better as the amount of data retrieved increases. It’s faster exactly when it matters most:
Benchmark | QC | Rust | Conclusion |
---|---|---|---|
findMany (25,000 records) | 55.0 ms | 185.0 ms | QC 3.4x faster |
findMany, take 2000 | 3.1 ms | 6.6 ms | QC 2.1x faster |
findMany with where and take 2000 | 10.8 ms | 13.3 ms | QC 1.2x faster |
findMany with orderBy and take 50 | 5.8 ms | 7.2 ms | QC 1.2x faster |
findMany with where, to-many join, and take 2000 | 72.3 ms | 92.3 ms | QC 1.3x faster |
findMany with where, to-many → to-one join, and take 2000 | 130.0 ms | 207.0 ms | QC 1.6x faster |
findMany with to-many relational filter, take 100 | 333.0 ms | 330.0 ms | Rust 1.01x faster |
findMany with deep relational filter, take 100 | 1.5 ms | 2.4 ms | QC 1.6x faster |
findMany with to-one filter, take 100 | 1.3 ms | 1.4 ms | QC 1.1x faster |
findMany with to-many → to-many → to-one relational filter, take 100 | 300.0 ms | 323.0 ms | QC 1.1x faster |
findUnique with take three of to-many join | 23.2 ms | 23.5 ms | QC 1.01x faster |
From our tests we’ve found that with large sets of data the Query Compiler was consistently faster than the Rust-based engine, up to three to four times faster in some cases. When only small sets of data are returned both implementations perform effectively the same. The Query Compiler gives a large benefit with no downside to existing Prisma ORM users.
These examples are just the first benchmarks, however. We’re planning on expanding these benchmarks and also running them in constrained environments, like AWS Lambda or Cloudflare Workers, so that we can be confident in our numbers. Additionally, we’ll be continuing to improve our implementation for added efficiencies and benefits.
Embracing the Future: Prisma ORM 7 and Beyond
We’re very excited about what this means for Prisma ORM users. The breakthrough performance and reduced bundle size not only make your apps faster and more efficient, but also us to more rapidly innovate. In the coming months, starting with a Preview release, we will invite you to try out these improvements. Shortly after that, Prisma ORM 7 will fully embrace the Query Compiler, marking the transition to a new era in how Prisma communicates with your databases.
As always, our focus in on our community and we’d love to hear your thoughts!
- Keep up with the latest updates and join the conversation on GitHub
- Ask us burning questions on Discord in our dev AMAs
- Even run the benchmarks yourself!
Don’t miss the next post!
Sign up for the Prisma Newsletter