prisma icon indicating copy to clipboard operation
prisma copied to clipboard

fix(client): Ensure `getDMMF` gets called only once

Open SevInf opened this issue 3 years ago • 3 comments

Problem: when we have a freshly instantiated client (haven't done any queries yet) and we execute multiple queries at the same event loop tick, each one of them will start getDMMF request, which could be quite slow.

Fixed by caching the results promise first time getDMMF is called and returning the same promise for subsequent calls.

Fix #14695

SevInf avatar Aug 09 '22 10:08 SevInf

I read this comment https://github.com/prisma/prisma/issues/14695#issuecomment-1209226061

Runtime: 1.863s
Runtime: 1.756s
Runtime: 1.756s

However, I get

Runtime: 4.381s
Runtime: 320.656ms
Runtime: 261.909ms

(With the user repro and full schema)

It might be worth investigating passing a JS object from Rust instead of a json string. wdyt?

millsp avatar Aug 09 '22 13:08 millsp

Sorry, forgot to push. Can you check now? The difference is that DMMFHelper creation is also moved into callOnce

SevInf avatar Aug 09 '22 13:08 SevInf

Awesome, thanks for the quick fix!

millsp avatar Aug 09 '22 13:08 millsp