RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.89k stars 81 forks source link

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

Open leemurus opened 3 weeks ago

leemurus commented 3 weeks ago

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:

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

RobertCraigie commented 3 weeks ago

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 commented 3 weeks ago

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.