-
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
Compiled model performance trends #33483
Comments
Note: see profiling session done by @muzopraha in #33495: |
This also shows regression for non-compiled models. Is a separate issue needed to track that? |
@stevendarby yeah, that's true - we'll discuss this in the team as well. |
@stevendarby @roji We discussed the regression in 8.0 at the time, and it was considered acceptable because if people had slow model building performance then they could use compiled models! Oh, the irony. |
@ajcvickers Irony aside, it's also not really true in all cases - for example, if you use query filters? |
@stevendarby Agreed. |
Is it a reasonable workaround, for now, to compile the model with EF Core 7, but then upgrade packages and run with v8 or v9? It doesn't crash and burn immediately, but I'd like to know if that's a completely unsupported mix. Thanks. Not sure how surprising this is, but when I encountered this issue, I discovered that AOT doesn't really improve the model init time of compiled models. (Leaving aside the fact queries won't run on AOT). |
No, it's completely unsupported. A "better" workaround would be to use some post-processing script to remove the slow calls added in the newer code. Most of them will be just computed lazily when not using NativeAOT. |
This is the proposed action plan to deal with this regression:
|
Is this going to be taken care of for .NET 9.0? This has become almost intolerable for our app. It is a short-lived application but the initial connection to the database takes 1-5 minutes depending on the hardware specs. That initial connection takes more time than the whole rest of the app. I am really hopeful this can be given high priority. |
@TonyValenti
It`s a part of ps1 script (for adding\removing migrations), that removes slow code in CompiledModel. |
My leadership would consider that a brittle approach and would not allow us to use that. I'm really hopeful this gets significant investment. |
Hi @AndriySvyryd - I really, really, really want to make sure this gets resolved for 9.0. |
@TonyValenti I can't tell exactly when or what, but something will be done about this for 9.0 |
I'm so glad this has priority. These performance challenges are really killing us. Is there a method (that would work with both compiled and non-compiled models) that we could call that would cause EFCore to generate/cache whatever information is necessary? In one of our apps, we'd like to experiment with launching a background tread that handles this initialization so that when a user wants to create a database, they're not waiting for minutes. |
@TonyValenti Calling |
Hi @AndriySvyryd - That helped but I think that doesn't fully initialize everything. On my PC, with no tweaks, the first database creation takes 43 seconds. What can I do that will cause everything to preload that a database creation would cause? |
@TonyValenti That might be due to a different issue that is now fixed in 9.0. Try also calling |
@AndriySvyryd - Thank you! That did it!
In 9.0, do you think something like this will still be necessary or do you think that it is possible that out of the box, we'll be able to hit the 3-second mark like that? |
@TonyValenti The second line might not be necessary. But I think you'll still need to prebuild the compiled model to get this experience even with the improvements. |
The critical part has been completed. Additional work is tracked in other issues. |
@ajcvickers Would it be possible to re-run your tests on the same machine so we can measure the improvements? |
I reran some of the benchmark scenarios on my machine. But I measured this, which should be more representative for normal app first query: using var context = new BlogsContext();
var model = context.Model.GetRelationalModel(); I was also using Release builds and the corresponding version of
So, it looks like the compiled model in 8 does improve the startup time (at the cost of the size). The additional code added in 9 for NativeAOT can make it worse in some cases, but now it isn't generated by default. And I wouldn't recommend using And the reason to consider using NativeAOT is that the startup time becomes 0.4s! (But it takes around 8 minutes to compile) |
Can you compare to 6/7 on the same machine please? I'm particularly interested in the normal model compile time, which regressed in 8/9 compared to 6/7. #33483 (comment) |
Model building is expected to take longer as we add more features, even if your model doesn't use them. We plan to rearchitect the conventions infrastructure at some point - #9329, but it's unclear how much impact it will have in practice until it's implemented. For now, we are focusing on improving the compiled model. |
In investigating the compiled model changes in EF9, I noticed that things were taking quite a lot longer than expected, so I did some analysis.
The model here is the one used in the samples: https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Miscellaneous/CompiledModels
The first issue is that, for this sample model with 449 entity types, 6390 properties, and 720 relationships, the startup time is now worse when using a compiled model.
By startup time, I mean wall clock time to run the following:
My suspicion that a lot of this is assembly loading and/or JIT, based on the increase in DLL size across releases:
Related to all this is that the time to run
dotnet ef dbcontext optimize
on this same model has increased very dramatically in EF9.dbcontext optimize
(s)The text was updated successfully, but these errors were encountered: