-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Possibly reading .env file and schema twice #19117
Copy link
Copy link
Open
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: .envtopic: bunBun is a fast all-in-one JavaScript runtimeBun is a fast all-in-one JavaScript runtimetopic: prisma-clienttopic: schema file
Description
Bug description
While investigating why Bun crashes when trying to use Prisma, I noticed that prisma is reading .env and possibly the schema file twice. This is duplicate work that would impact start time of projects using Prisma. I'm not 100% confident that this isn't a bug in Bun.
If we run the same file in Node with "System Trace" in Instruments:
xcrun xctrace record --template "System Trace" --launch (which node) (realpath index.mjs)We can see that the same file run in node calls open() 77 times.
If we change the code to only import {PrismaClient} from "@prisma/client";, the number of calls to open() drops to 70:
It would honestly be easier to see which specific files are opened if using strace since strace will show file paths, but I'm not at a linux machine right now
How to reproduce
Code:
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const user = await prisma.user.create({
data: {
name: "Alice",
email: "alice@prisma.io",
},
});
console.log(user);
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});Schema:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}Expected behavior
Only read .env once
Prisma information
// Add your schema.prisma// Add your code using Prisma ClientEnvironment & setup
- OS: macOS
- Database: SQLite
- Node.js version: v20.0.0
Prisma Version
prisma : 4.10.1
@prisma/client : 4.10.1
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine aead147aa326ccb985dcfed5b065b4fdabd44b19 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli aead147aa326ccb985dcfed5b065b4fdabd44b19 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm : @prisma/prisma-fmt-wasm 4.10.1-1.80b351cc7c06d352abe81be19b8a89e9c6b7c110
Default Engines Hash : aead147aa326ccb985dcfed5b065b4fdabd44b19
Studio : 0.481.0Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: .envtopic: bunBun is a fast all-in-one JavaScript runtimeBun is a fast all-in-one JavaScript runtimetopic: prisma-clienttopic: schema file



