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

withZod = true increases generation times by several magnitudes; any way to improve? #75

Open
andenacitelli opened this issue Mar 21, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@andenacitelli
Copy link

andenacitelli commented Mar 21, 2023

Bug description

I'm seeing this package take two magnitudes longer than any of my other generators. I know this generates a lot of code, but this still feels high and really hurts the developer experience, especially if prototyping with frequent schema changes.

Running with all defaults takes ~10 seconds:

generator trpc {
  provider             = "prisma-trpc-generator"
  withZod              = true
  withMiddleware       = false
  withShield           = false
  contextPath          = "@endwise/server/trpc"
  trpcOptionsPath      = "@endwise/server/trpc"
}

image

Zod schemas seem to take 90%+ of this time, as setting withZod to false decreases the time down to 366ms.

image

How to reproduce

npm i prisma-trpc-generator

Add generator to Prisma schema:

generator trpc {
  provider             = "prisma-trpc-generator"
  withZod              = true
  withMiddleware       = false
  withShield           = false
  contextPath          = "@endwise/server/trpc"
  trpcOptionsPath      = "@endwise/server/trpc"
}

npx prisma generate

Expected behavior

Runtime in the same ballpark as other generators. Zod schemas are not a negotiable for me, as I value the type safety extremely highly.

Prisma information

Schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator zod {
  provider         = "zod-prisma-types"
  createModelTypes = false
}

generator trpc {
  provider             = "prisma-trpc-generator"
  withZod              = true
  withMiddleware       = false
  withShield           = false
  contextPath          = "@endwise/server/trpc"
  trpcOptionsPath      = "@endwise/server/trpc"
}

generator client {
  provider = "prisma-client-js"
  output   = "./generated/prisma"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model CacheEntry {
  key   String @id @map("_id")
  value String
}

model User {
  // App-Agnostic
  id         String  @id @default(auto()) @map("_id") @db.ObjectId
  email      String  @unique
  customerId String?

  // App-Specific
  tasks         Task[]
  epics         Epic[]
  projects      Project[]
  schedules     Schedule[]
  locations     Location[]
  taskTemplates TaskTemplate[]
}

model Task {
  id          String            @id @default(auto()) @map("_id") @db.ObjectId
  title       String
  description String? // Rich-Text
  recurrence  RecurrenceOptions @default(NONE) // TODO: Needs fleshed out a bit; aim for Google Calendar level of customizability
  locations   Location[]
  // TODO: Location blacklist
  size        TaskSize          @default(MEDIUM) // Defaults to Medium, but will likely be set by GPT or the user.
  start       DateTime?
  end         DateTime?
  createdAt   DateTime          @default(now())
  updatedAt   DateTime          @updatedAt

  // TODO: Parent Task

  // TODO: 1:N Dependencies

  // Linkage
  User           User          @relation(fields: [userEmail], references: [email])
  userEmail      String        @unique
  Epic           Epic?         @relation(fields: [epicId], references: [id])
  epicId         String?       @db.ObjectId
  Project        Project?      @relation(fields: [projectId], references: [id])
  projectId      String?       @db.ObjectId
  TaskTemplate   TaskTemplate? @relation(fields: [taskTemplateId], references: [id])
  taskTemplateId String?       @db.ObjectId
}

model Epic {
  id String @id @default(auto()) @map("_id") @db.ObjectId

  // Linkage
  User      User?    @relation(fields: [userEmail], references: [id])
  userEmail String?  @db.ObjectId
  tasks     Task[]
  Project   Project? @relation(fields: [projectId], references: [id])
  projectId String?  @db.ObjectId
}

model Project {
  id String @id @default(auto()) @map("_id") @db.ObjectId

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [id])
  userEmail String? @db.ObjectId
  epics     Epic[]
  tasks     Task[]
}

model Location {
  id          String @id @default(auto()) @map("_id") @db.ObjectId
  nickname    String
  latitude    Float
  longitude   Float
  radiusMiles Int // Radius in which user is considered to be at this location

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [id])
  userEmail String? @db.ObjectId
  Task      Task?   @relation(fields: [taskId], references: [id])
  taskId    String? @db.ObjectId
}

model TaskTemplate {
  id    String @id @default(auto()) @map("_id") @db.ObjectId
  tasks Task[]

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [email])
  userEmail String? @unique
}

model Schedule {
  id        String     @id @default(auto()) @map("_id") @db.ObjectId
  timeslots Timeslot[]

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [email])
  userEmail String? @unique
}

model Timeslot {
  id           String @id @default(auto()) @map("_id") @db.ObjectId
  startSeconds Int // # of Seconds Into Week
  endSeconds   Int // # of Seconds Into Week

  // Linkage
  Schedule   Schedule @relation(fields: [scheduleId], references: [id])
  scheduleId String   @db.ObjectId
}

/// JIRA-esque Task Statuses
enum TaskSize {
  SMALL
  MEDIUM
  LARGE
  EXTRA_LARGE
}

enum DayOfTheWeek {
  MONDAY
  TUESDAY
  WEDNESDAY
  THURSDAY
  FRIDAY
  SATURDAY
  SUNDAY
}

enum RecurrenceOptions {
  NONE
  DAILY
  WEEKLY
  MONTHLY
}

Environment & setup

  • OS: Windows
  • Database: MongoDB (shouldn't matter)
  • Node.js Version: v18.14.2

Prisma Version

Environment variables loaded from .env
prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at ..\..\node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at ..\..\node_modules\@prisma\engines\migration-engine-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
@omar-dulaimi omar-dulaimi added the enhancement New feature or request label May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants