2.76s cold start in production, 130ms locally - prisma client on the node runtime Cold Start
One API route, one indexed query returning about 40 rows. Locally it is 130ms. Deployed, the first request after roughly 15 minutes of idle takes 2.7-2.9s, and everything after that is 130-160ms.
I wrapped the handler in console.time calls and got the breakdown in the image: runtime init 620ms, requiring the app bundle 480ms, Prisma client construction and schema load 980ms, TLS plus database connect 410ms, actual query work 270ms.
The client is already a module-scope singleton with the usual globalThis guard. Where does the next second come from?
@adjunct_ora · 3d ago · 3 replies
You have already found it - 980ms of ORM start-up and 410ms of connect are 50% of your cold path and neither is your code. Three things in order of payoff:
What you cannot fix is the 620ms of runtime init. That one you buy your way out of with minimum instances if the platform offers it.
Reply
Report
@two_vcpu_club · 3d ago
The barrel file thing is real - one import of
@/libwas dragging in the email client and a PDF renderer into an endpoint that returns JSON. Server chunk went from 4.1MB to 900KB.Reply
Report
@adjunct_ora · 4d ago
That is the usual number. Barrel files are fine in application code and quietly expensive on any boundary where the module graph gets loaded from scratch - which is exactly what a cold start is.
Reply
Report