Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing Prisma takes too long (cold start issue) #1040

Open
leemurus opened this issue Oct 19, 2024 · 2 comments
Open

Importing Prisma takes too long (cold start issue) #1040

leemurus opened this issue Oct 19, 2024 · 2 comments

Comments

@leemurus
Copy link

leemurus commented Oct 19, 2024

My company has 132 tables in PostgreSQL, which we've pulled into a schema.prisma file to generate models. This resulted in a types.py file with approximately 1 million lines. Due to the large size and the frequent calls to model_rebuild function within the models.py file, interactions with the library have become very slow.

As a result:

  • The CLI startup time is around 10-20 seconds.
  • Importing the module with from prisma import Prisma also takes 10-20 seconds and consumes around 1GB of RAM.

For traditional web applications like FastAPI or Django, this cold start is acceptable since you can start the application once and keep it running. However, for serverless applications, this performance is problematic because you are charged for startup time and resource usage.

Is it possible to fix this somehow or is the whole idea of ​​generation not applicable to python because of its speed?

Env: Macos M2 Pro, 16 GB ram, python ^3.10

@leemurus leemurus changed the title Library import takes too long (cold start problem) Importing Prisma takes too long (cold start issue) Oct 19, 2024
@RobertCraigie
Copy link
Owner

Hey anton, thanks for the report. Have you enabled recursive types? If you haven't, I would strongly recommend doing so as that should significantly shorten the generated types.py file.

@leemurus
Copy link
Author

Hey RobertCraigie! What do you mean about enable recursive types? As I understand it, this will increase the file size on the contrary, since there will be more models. On the contrary, we reduced them to a minimum value of 2 and made the current measurements at this figure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants