-
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
Precompiled queries #25009
Comments
Alternatively instead of implementing this as a source generator it could be a design-time tool that uses Roslyn and avoids the issues related to loading user assemblies and resolving types used in queries. |
@AndriySvyryd yeah. To sum up an internal conversation with @jaredpar:
So yeah, we'll probably go with a design-time tool (e.g. CLI command). The general plan outlined above should still apply to that (and the need for isolating the user assemblies is no longer relevant). |
To improve trimming, we can define a feature switch for query compilation to allow all that code to be trimmed if all queries are precompiled. |
Another relevant doc: https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md I wonder if we can automatically trim that code when publishing AOT, without requiring another gesture from the user - if possible, we should avoid having too many knobs and switches which users have to set to get to the right place. |
Note that this includes AOT execution of the first part of the query pipeline; the is the part the generates the materializer (and so uses code generation), and has no access to parameter values. It notably does not include SQL generation (that's #29753). |
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Part of #25009 remove unnecessary test changes cleanup
Fix materializer code to replace non-primitive constants with liftable constants. Precompilation is opt-in in QueryCompilationContext, switched on for relational, off for everything else. Part of #25009
Fix materializer code to replace non-primitive constants with liftable constants. Precompilation is opt-in in QueryCompilationContext, switched on for relational, off for everything else. Part of #25009
Fix materializer code to replace non-primitive constants with liftable constants. Precompilation is opt-in in QueryCompilationContext, switched on for relational, off for everything else. Part of #25009
Fix materializer code to replace non-primitive constants with liftable constants. Precompilation is opt-in in QueryCompilationContext, switched on for relational, off for everything else. Part of #25009
Fix materializer code to replace non-primitive constants with liftable constants. Precompilation is opt-in in QueryCompilationContext, switched on for relational, off for everything else. Part of #25009
I'm closing this as complete for 9. We certainly have remaining issues and improvements to work on, but we can track those separately. |
This tracks the precompiled query feature, where EF generates interceptors at publish time to intercept static LINQ query operators and execute the query directly, without going through compilation. This:
Note that although this is a prerequisite to NativeAOT support, precompiled queries can be used in non-NativeAOT applications to get the above performance benefits (faster execution and startup time).
The main subtasks are tracked on the general NativeAOT epic.
dotnet publish
, and possibly also intodotnet ef
for manual precompilation.** PREVIOUS DESIGN THOUGHTS **
General design
When a LINQ query is first encountered, EF "compiles" it, producing a code-generated shaper, SQL (for relational databases), etc. This process is both a bit long (increasing startup times), and incompatible with AOT environments (since code generation is used at runtime). While several approaches have been discussed in the past to improve this (e.g. #16496), with the advent of source generators we have some new possibilities. I've done some work on a proof-of-concept source generator which identifies EF queries and precompiles them; the work is far from complete but indicates that the approach is feasible.
In a nutshell, we would:
The final code added by the source generator would look something like the following:
Additional notes:
EDIT: Following internal discussion it has become clear that doing this as a source generator isn't practical (see #25009 (comment) below). Instead, this would be a design-time CLI command or similar.
This would most likely be opt-in-only (via a csproj property), and probably makes most sense in Release builds.When loading user assemblies (and their dependents), we probably want to isolate them in their own AssemblyLoadContext. This isn't trivial - we need to take Roslyn-provided syntax tree and semantic models (default assembly loader), transform them into an expression tree, and pass that into the query pipeline isolated inside the special AssemblyLoadContext. In my prototype, the default AssemblyLoadContext is used to avoid these issues.The text was updated successfully, but these errors were encountered: