Skip to content

fix(client): prevent caching of createMany queries to avoid cache bloat and possible node.js crashes - #29382

Merged
jacek-prisma merged 3 commits into
prisma:mainfrom
shakim:main
Mar 25, 2026
Merged

jacek-prisma merged 3 commits into
prisma:mainfrom
shakim:main

Conversation

@shakim

@shakim shakim commented Mar 24, 2026 •

Copy link
Copy Markdown

createMany operations inherently have unstable cache keys due to varying row counts and parameter de-duplication.

createMany operations are characterized by large cache keys and very large query plans. In large batches, the cache will consume several GB of memory that will not be evicted by the GC even after the query is complete because the plans are still referenced by the cache itself.

This fix opts out of caching such queries with the following rationale:

  1. Such queries will most likely create cache-misses and so caching them is ineffective
  2. When running batch load/update workloads, these query plans will evict valid queries from the cache thus creating an advert effect on performance

Fixes: #29331

Summary by CodeRabbit

  • Bug Fixes

    • Reduced query-plan cache growth by skipping single-query caching for high-volume bulk create operations, lowering memory use and improving bulk write efficiency.
  • Tests

    • Added a comprehensive functional test suite (matrix, provider-specific schema setup, and stress tests) that seeds data and runs parameterized create-many scenarios to validate performance and correctness under load.

…at and possible node.js crashes

`createMany` operations inherently have unstable cache keys due to varying row counts and parameter de-duplication.

`createMany` operations are characterized by large cache keys and very large query plans. In large batches, the cache will consume several GB of memory that will not be evicted by the GC even after the query is complete because the plans are still referenced by the cache itself.

This fix opts out of caching such queries with the following rationale:
1. Such queries will most likely create cache-misses and so caching them is ineffective
2. When running batch load/update workloads, these query plans will evict valid queries from the cache thus creating an advert effect on performance

Closes prisma#29331
@CLAassistant

CLAassistant commented Mar 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1f00b8b3-e48e-4348-bbc9-8ba4d6c893ab

📥 Commits

Reviewing files that changed from the base of the PR and between 9d556bd and 7cc1a4c.

📒 Files selected for processing (1)
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts

Walkthrough

Exclude createMany and createManyAndReturn from single-query plan cache reads/writes in ClientEngine and add a functional test suite (matrix, provider schema, and stress tests) to validate behavior and parameter variation patterns.

Changes

Cohort / File(s) Summary
Query Plan Caching Logic
packages/client/src/runtime/core/engines/client/ClientEngine.ts
Added an isCacheable guard so single-query cache operations (getSingle/setSingle) are skipped for createMany and createManyAndReturn; batch caching and compilation paths remain unchanged.
Functional Test Suite
packages/client/tests/functional/issues/29331-query-plan-cache-bloat/_matrix.ts, packages/client/tests/functional/issues/29331-query-plan-cache-bloat/prisma/_schema.ts, packages/client/tests/functional/issues/29331-query-plan-cache-bloat/tests.ts
Added test matrix, provider-specific Prisma schema (Contact, ContactAnalytics) and a parameterized stress test that repeatedly calls createMany with varied field patterns and asserts row counts.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preventing caching of createMany queries to avoid cache bloat and Node.js crashes, which is the primary focus of the changeset across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/client/tests/functional/issues/29331-query-plan-cache-bloat/tests.ts`:
- Around line 20-51: The test hooks are declared out of lifecycle order:
afterEach is above beforeEach; swap their positions so beforeEach (containing
prisma.contact.createMany and prisma.contactAnalytics.createMany) comes before
afterEach (containing prisma.contactAnalytics.deleteMany and
prisma.contact.deleteMany) to follow conventional setup → teardown ordering and
improve readability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37127c63-e2d9-47bf-ad55-ca8f64bcade9

📥 Commits

Reviewing files that changed from the base of the PR and between 74839a9 and 9d556bd.

📒 Files selected for processing (4)
  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/tests/functional/issues/29331-query-plan-cache-bloat/_matrix.ts
  • packages/client/tests/functional/issues/29331-query-plan-cache-bloat/prisma/_schema.ts
  • packages/client/tests/functional/issues/29331-query-plan-cache-bloat/tests.ts

@codspeed

codspeed Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 30 skipped benchmarks1


Comparing shakim:main (7cc1a4c) with main (4131568)

Open in CodSpeed

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@aqrln aqrln added this to the 7.6.0 milestone Mar 25, 2026
@jacek-prisma
jacek-prisma merged commit 5b420f8 into prisma:main Mar 25, 2026
240 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory consumption increased significantly in Prisma 7 in comparison to Prisma 6

4 participants