Prisma 7: every PrismaClient decodes its own copy of the parameterization schema (~31 MB heap per client)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, postgresql, typescript
- Domain
- backend, databases, performance
Research direction
Start in the generated client runtime at runtime/client.js and runtime/client.mjs, then trace the decoder called by the client engine constructor. Check whether the decoded parameterization schema is read-only and whether caching it per input object preserves behavior. Done means clients from the same generated client share the decoded graph and the reproduction shows near-zero extra heap per client.
Written by the indexing model from the issue text.
Description
Bug description
With the query compiler (Prisma 7, driver adapters), each new PrismaClient(...) decodes the generated client's parameterizationSchema into a fresh object graph. For our schema that is about 31 MB of JS heap per client. An app that keeps one client per tenant (a multi-tenant AWS Lambda holding a small LRU of tenant clients) pays that for every client, even though every graph is identical.
On Prisma 6.9 with the same schema, each extra client cost about 7 MB of RSS. The upgrade to 7.10 is what pushed our 512 MB Lambda over its memory limit.
Where it happens
In @prisma/client 7.10.0 runtime/client.js (minified names), the client engine's constructor does:
this.#s = mr.deserialize(t.parameterizationSchema, enumLookup)
mr.deserialize calls a decoder, function Ba(e){return new Li(e).deserialize()}, which turns the base64 graph into {strings, inputNodes, outputNodes, roots}. t.parameterizationSchema is the same object for every client of one generated client. As far as we can tell, the decoded graph is read-only after construction: nothing writes to its arrays or objects.
Reproduction
const { PrismaClient } = require("./generated/client");
const { PrismaPg } = require("@prisma/adapter-pg");
const heap = () => { gc(); gc(); return process.memoryUsage().heapUsed; };
const make = () => new PrismaClient({ adapter: new PrismaPg({ connectionString: "postgresql://u:[email protected]:1/x" }) });
const clients = [make()];
const before = heap();
for (let i = 0; i < 4; i++) clients.push(make());
console.log(((heap() - before) / 4 / 1048576).toFixed(1), "MB per extra client");
Run with node --expose-gc. No database connection is needed: constructing the client is enough. We see 31 MB per extra client.
A possible fix
We tested memoising the decoder per input object (WeakMap), in both runtime/client.js and runtime/client.mjs:
var cache = new WeakMap;
function Ba(e){ let t = cache.get(e); return t || (t = new Li(e).deserialize(), cache.set(e, t)), t }
Measured with that change:
- Heap per extra client: 31 MB before, 0.15 MB after.
- Our real Lambda handler, 13 tenants, 5 cached clients: peak RSS 605 MB before, 291 MB after.
- Our full api, lambda and core test suites pass with it.
We are not patching our installed Prisma. For now we give the Lambda more memory and cache fewer clients, so a fix in Prisma itself would let us undo both.
Expected behavior
Clients created from the same generated client share one decoded parameterization schema, or decode it lazily, so the cost per extra client is close to zero.
Environment
prismaand@prisma/client7.10.0,prisma-client-jsgenerator,@prisma/adapter-pg- PostgreSQL
- Node.js 24 (AWS Lambda nodejs runtime)
- Dominant language
- TypeScript
- Stars
- 47.8k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 227
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from prisma/orm
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
get-platform: distros with ID_LIKE=alpine are not detected as musl, so glibc engines are used on Alpine-based imagesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prisma/orm#31281 · 1 comment ·
Maintainers usually reply within 1 day
-
adapter-pg: connectToShadowDb connects to the main database when built from a connection stringMay be free again @cestercian claimed this 10 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
prisma/orm#31196 · 1 comment ·
Maintainers usually reply within 1 day
-
[Prisma 8] Type-check time grows exponentially with chained .include() callsPossibly taken @SiKreuz claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
prisma/orm#31161 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
prisma/orm#31125 · 4 comments · 6 reactions ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prime-radiant-inc/evener#8335 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel-labs/ui#1921 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 65/100
microsoft/monaco-editor#5626 ·
Maintainers usually reply within 1 day