Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.76k stars 104 forks source link

Release client generator slower than debug client generator #260

Closed bangbaew closed 1 year ago

bangbaew commented 1 year ago

When I run Prisma cli generate with --release flag, it's stuck at Prisma schema loaded from prisma/schema.prisma for a very long time (5 minutes on okteto cloud), while the debug run just executes immediately (but needs to compile debug dependencies, so if it's on cloud, I would use release dependencies to run it).

image

image Prisma cli itself informed that the client was created in 1.00s, but the docker timer was 186.1s, but with the debug run, it will exactly be 1.00s after the cli started as the cli said. I don't think the release binary should be slower than the debug binary.

Brendonovich commented 1 year ago

My guess is that between 'Prisma schema loaded...' and 'Generated Prisma Client...' your CLI crate had to compile, since it gets ran with cargo run. You're building everything else in release mode, but cargo run will just use debug mode, so all your dependencies are recompiling in debug mode, the CLI is running, and then the generator is triggered - which only takes 1.00s. If this is the case I'm not quite sure what to recommend yet. I'll think about it.

bangbaew commented 1 year ago

My guess is that between 'Prisma schema loaded...' and 'Generated Prisma Client...' your CLI crate had to compile, since it gets ran with cargo run. You're building everything else in release mode, but cargo run will just use debug mode, so all your dependencies are recompiling in debug mode, the CLI is running, and then the generator is triggered - which only takes 1.00s. If this is the case I'm not quite sure what to recommend yet. I'll think about it.

Thanks for fast response, if there's no other way, can you make it log? so, I could tell that the build process is not dead as long as I see what's going on inside the cli between 'Prisma schema loaded...' and 'Generated Prisma Client...'.

Brendonovich commented 1 year ago

I'm not sure I can, since that part is out of my control. One idea is to make the CLI cargo install-able, but that still has the problem of requiring dependency caching. For your case, adding --release to the Cargo alias should work, I just wonder if it's a good enough solution.

bangbaew commented 1 year ago

I'm not sure I can, since that part is out of my control. One idea is to make the CLI cargo install-able, but that still has the problem of requiring dependency caching. For your case, adding --release to the Cargo alias should work, I just wonder if it's a good enough solution.

Works perfectly! thanks a lot. image

Now I just have to create an alias prisma-release = "run --release --bin prisma" and add RUN sed -i 's/cargo prisma/cargo prisma-release/g' prisma/schema.prisma to my Dockerfile, so it can replace the provider with the release version when deploying and i'll still be able to run debug generate when i'm developing, now it saves me a lot of time, at least 5 minutes on each deploy since okteto cloud isn't caching the layers for me.