News

Compiled Models Quicken App Startups in Entity Framework Core 6.0 Preview 5

Some six years in the making, an effort to quicken app startup times in Entity Framework Core via compiled models has been realized in the new v6.0 Preview 5.

As detailed in the Plan for Entity Framework Core 6.0, "Compiled models will allow the generation of a compiled form of the EF model. This will provide both better startup performance, as well as generally better performance when accessing the model."

The effort was proposed way back in March 2015 in a GitHub issue titled "Reduce EF Core application startup time via compiled models." That moved from In Progress to Completed last month. It must have been proposed in the very earliest stages of Microsoft's "Core" initiative (originally called Entity Framework 7) because EF Core 1.0 didn't debut until June 2016.

This month, Microsoft's Jeremy Likness announced initial support in EF Core 6.0 Preview 5. "This release includes the first iteration of compiled models. If startup time for your application is important and your EF Core model contains hundreds or thousands of entities, properties, and relationships, this is one release you don’t want to ignore," said the senior program manager - .NET Data, .NET.

Broadly speaking, the model generation is done by optimization via command-line interface (CLI) tooling to generate source code files that can be used in a project to build a compiled model.

For example, the 2015 issue mentioned above included this CLI command:

dotnet ef dbcontext optimize -c MyContext -o MyFolder -n My.Namespace

while Likness this month reported using this command:

dotnet ef dbcontext optimize -output-dir MyCompiledModels --namespace MyCompiledModels

That command (along with other steps) optimizes the "Build model" step of executing a first query, as depicted here (with cache boxes shown disabled for benchmarking):

First Query Execution
[Click on image for larger view.] First Query Execution (source: Microsoft).

Likness reported a 10x performance boost in one example with 449 entity types, 6,390 properties and 720 relationships. He pointed to this graphic -- comparing startup times for compiles and non-compiled models -- as an example of how startup times remain fast even if a model grows larger:

Startup Time by Model Size
[Click on image for larger view.] Startup Time by Model Size (source: Microsoft).

While that's an obvious "pro" for the scheme, Likness noted that the model must be manually synchronized by regenerating it when its definition or configuration change, which he deemed a "con." Also on the regenerating front, when asked by a developer if compiled models generated in the preview would be usable in the full EF Core 6.0 RTM release, Likness replied: "Like other generated code, the expectation is that you would have to regenerate the model at a minimum each minor release. There is an extensibility point being made so that you can customize the model without having to rewrite the code every time the compiled model changes. The extensibility API is expected to be backwards compatible through future releases."

Other "cons" he listed include lack of support for:

Developers are invited to find and upvote associated issues for the above if they are deemed critical to success. The new functionality can be tested by downloading the latest EF Core 6.0 preview and the latest EF Core CLI.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events