Skip to content

feat(perf): ORM-623 add cache for migration data - #5471

Merged
FGoessler merged 9 commits into
mainfrom
feat/ORM-623-migrate-perf
Jun 12, 2025
Merged

feat(perf): ORM-623 add cache for migration data#5471
FGoessler merged 9 commits into
mainfrom
feat/ORM-623-migrate-perf

Conversation

@FGoessler

@FGoessler FGoessler commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

This PR improves the performance of the prisma migrate dev command by avoiding redundant shadow database work.

During the execution of prisma migrate dev Prisma creates a DatabaseSchema based of the list of existing migrations for up to 3 times. In most cases with the exact same input of migrations and hence same output of DatabaseSchema. This is a costly operation as it needs to apply the migrations to a shadow database. This becomes especially slow when connecting to a remote database like Prisma Postgres.

Prisma now caches this result after the first computation. There are still cases where the list of migrations provided as input can vary between the invocations. Hence the cache uses a hash of the provided migrations as cache key.

This implementation was a bit tricky as the DatabaseSchema struct and parts of the SqlDatabaseSchema (the ConnectorData) are type erased constructs. This made a simple clone impossible and I had to do some workarounds. Cloning is required so one variant of the DatabaseSchema can be stored in the cache while another clone can be passed on for further processing in the diffing process.

In my testing against Prisma Postgres this change decreased the runtime by ~50%. From ~2 minutes before my changes to now ~1 minute.

@FGoessler FGoessler added this to the 6.10.0 milestone Jun 11, 2025
@codspeed-hq

codspeed-hq Bot commented Jun 11, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5471 will not alter performance

Comparing feat/ORM-623-migrate-perf (bf7f7ce) with main (82e5178)

Summary

✅ 11 untouched benchmarks

@github-actions

github-actions Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

WASM Query Engine file Size

Engine This PR Base branch Diff
Postgres 2.188MiB 2.184MiB 4.407KiB
Postgres (gzip) 876.182KiB 875.160KiB 1.023KiB
Mysql 2.154MiB 2.149MiB 4.615KiB
Mysql (gzip) 861.318KiB 859.910KiB 1.409KiB
Sqlite 2.063MiB 2.058MiB 4.456KiB
Sqlite (gzip) 826.826KiB 825.455KiB 1.372KiB

@FGoessler
FGoessler marked this pull request as ready for review June 12, 2025 05:36
@FGoessler
FGoessler requested a review from a team as a code owner June 12, 2025 05:36
Comment thread schema-engine/connectors/schema-connector/src/migrations_directory.rs Outdated
Comment thread schema-engine/connectors/schema-connector/src/database_schema.rs
Comment thread schema-engine/commands/src/migration_schema_cache.rs Outdated
Comment thread schema-engine/commands/src/migration_schema_cache.rs Outdated
@FGoessler
FGoessler requested a review from jacek-prisma June 12, 2025 11:40
Comment thread schema-engine/commands/src/migration_schema_cache.rs Outdated
@FGoessler
FGoessler merged commit 6afa645 into main Jun 12, 2025
@FGoessler
FGoessler deleted the feat/ORM-623-migrate-perf branch June 12, 2025 13:30
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.

2 participants