-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance regression in model building in Entity Framework Core 7 #29642
Comments
Any chance you can create a SQL migration script for both versions and post the results? ( |
Sure, here you can find both SQL files in the repository I shared: https://github.com/MaQy/EfCoreMigrationsBenchmark/blob/master/migrations_6.0.11.sql As I mentioned in my initial post, the SQL statements are basically the same and take the same time to execute. It's the time between migrations that takes longer. In the traces I got from my own application with interceptors, EF Core 6 takes around 200-300 ms between migrations (that is, from the last SQL statement of a migration to the first SQL statement of the following one), while EF Core 7 takes around 700-1000 ms. I also added the script generation into the benchmark and the overhead is clearly visible:
|
Thanks @MaQy, I can indeed see that something is wrong and will investigate. |
I think I found it; when generating the migration script twice, I'm seeing Property.GetContainingForeignKeys called around 330 million times. The bulk of the calls seem to happen from Property.GetValueConverter, where #29073 added this for loop. It seems that in certain conditions we may be looping 10000 times for no reason. The same thing also seems to be happening in GetProviderClrType, which takes up 100 million of the 330 million calls. /cc @AndriySvyryd |
+1 for this. We're experiencing the exact same issue after upgrading to .NET7 & EF7. We're using Npgsql.EntityFrameworkCore provider. Migration now takes at least twice as long. |
Hi,
I have just migrated an application to Entity Framework Core 7 and noticed that executing the migrations for a new database takes twice or even three times longer than with Entity Framework Core 6. As far as I could see, adding interceptors, the actual SQL statements perform roughly the same, it's the time between migrations that takes longer (I guess building the operations, but I didn't go that deep).
I created a repo with a very simple project to showcase this scenario: https://github.com/MaQy/EfCoreMigrationsBenchmark
Even with just 5 migrations, 4 of them pretty small, the issue can be seen according to the results I got:
Include provider and version information
EF Core version: 7.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11 21H2
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: