feat(perf): ORM-623 add cache for migration data - #5471
Merged
Conversation
CodSpeed Performance ReportMerging #5471 will not alter performanceComparing Summary
|
Contributor
WASM Query Engine file Size
|
FGoessler
marked this pull request as ready for review
June 12, 2025 05:36
jacek-prisma
approved these changes
Jun 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the performance of the
prisma migrate devcommand by avoiding redundant shadow database work.During the execution of
prisma migrate devPrisma creates aDatabaseSchemabased 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 ofDatabaseSchema. 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
DatabaseSchemastruct and parts of theSqlDatabaseSchema(theConnectorData) are type erased constructs. This made a simplecloneimpossible and I had to do some workarounds. Cloning is required so one variant of theDatabaseSchemacan 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.