prisma: Other packages make Prisma load very slow
Bug description
Tested this with a file where I’m just importing the client:
const { PrismaClient } = require('@prisma/client')
With 2.23 this loads in under a second, whereas on 2.24 and beyond it takes roughly 12-13 seconds each time.
This is a bit of a major issue for us when it comes to our testing, and just generally slows down the dev flow. Is this a known issue, and is there any way to reduce the load time?
How to reproduce
Can add our schema if needed, just a bit large so didn’t add it right away.
Expected behavior
Load as fast as before.
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: 15.14.0
Prisma Version
2.28.0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (10 by maintainers)
We ran into this issue too, and it seems to be caused by the bug reported in #7808 (and fixed by #9295 in
3.1.0
). Basically when trying to import Prisma client, a call is made that looks like the following:Notice the double-quotes inside single quotes. These paths don’t exist, and so it seems Prisma resorts to searching every module inside node_modules, which is as reported very slow.
Testing with a simple
time node -e "require('@prisma/client')"
on my machine takes 1.3 seconds, but manually fixing the two lines in the generated files to remove the extra quotes causes the same command to take 0.6 seconds. If it’s helpful for anyone, we’ve incorporated somesed
commands into our CI/CD to automatically rewrite these double-quoted lines as a temporary speedup while we work on upgrading to a more recent Prisma version:I can confirm this is no longer an issue in
3.3
I did a clean start with the above minimal example and I can finally reproduce this!!
Even generate is quite slow:
Marking as regression. This will need more investigation.
I’m using Prisma inside of an Electron app. This is perhaps a not supported/intended use of Prisma. But FYI, when run by Electron,
process.cwd()
returns “/”. So thefindSync
call scans from the root directory which takes a long time (~60s).I’m working around this by running a build script that replaces
process.cwd()
withrequire('electron').app.getAppPath()
in the generated client code:This cuts down the time it takes to instantiate the Prisma client to ~10ms.
Ok it appears to be a package issue - if I install just the prisma packages it works fine, but something in our package list is causing problems.
Schema:
Dependencies:
And then testing it by just running this file:
I think it’s the same issue given https://github.com/prisma/prisma/issues/8484#issuecomment-895897833, and that this issue is perhaps mislabeled. It’s not (just) the version change but conflicts, as @jwld already pointed out, with other packages that’s causing the slow loading time. I just tried Prisma with
The instantiation is instant. So I think the two issues are related, and it’s uncertain whether version change is clearly isolated as the sole cause for the problem. But if you insist I’ll open another issue.