question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce EF Core application startup time via compiled models

See original GitHub issue

This an “epic” issue for the theme of generating a compiled model with fast loading and access times. Specific pieces of work will be tracked by linked issues.

Proposed for 6.0

Used by calling new tool commands (all parameters are optional)

dotnet ef dbcontext optimize -c MyContext -o MyFolder -n My.Namespace
Optimize-DbContext -Context MyContext -OutputDir MyFolder -Namespace My.Namespace
  • Add runtime annotation support to model #22031
  • Convert metadata extension methods to default interface implementations. #19213
  • Create a read-optimized implementation of IModel that can be used as the base for the compiled model #8258
  • Add API to set custom implementation types instead of objects
    • ValueGenerator (store non-lambda configuration separately)
    • ValueComparer and ValueConverter
  • Implement a generator that outputs the source code for a custom model implementation
    • Throw when the model contains non-serializable configuration like lambdas, proxy types and non-serializable expressions. Or if it’s using a read-optimized implementation.
    • Generate #nullable enable
    • Warn when using a model generated by an older version.
    • Warn when using a non-default model cache key.

Backlog

  • Consider discovering the model automatically instead of requiring ‘UseModel’, by using assembly-level attribute (#24893)
  • Consider adding a MsBuild task to generate the model at build-time (#24894)
  • Either move the members from the pubternal model interfaces to the public ones, so that they can have non-dynamic implementations or add a runtime annotation-based backup implementation. (#24895)
  • Generate compiled relational model (#24896)
    • Add tests that assert the relational model, view, query mapping and default mappings
  • Generate code for query filters when possible. (#24897)
  • Generate constructor bindings (#24898)
  • Generate code that builds the model lazily (#24899)
  • Rely on static binding instead of reflection for properties and fields (#24900)
  • Split out the mutable model implementation to a different assembly as it’s not needed when using compiled model (#24901)
  • Generate custom lazy loading and change tracking proxy types. (#24902)
  • Generate lambdas used in change tracking (#24904)
  • Generate code that normally depends on reflection types in the model (Type, MemberInfo, etc.) to avoid all reflection at runtime (#24903)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:119
  • Comments:94 (37 by maintainers)

github_iconTop GitHub Comments

18reactions
tobiasbunyancommented, Dec 8, 2017

Never mind the load time on a live application, the crippling amount of time you have to wait each time you start a debug session slashes productivity to almost nothing!!! This needs sorting out BIG TIME!

17reactions
lemkepfcommented, Feb 26, 2018

Any updates on if this will be added into EF Core any time soon?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Announcing Entity Framework Core 6.0 Preview 5
The start-up time for the first run consistently takes around two seconds on my laptop, with subsequent cached instances weighing in at about ......
Read more >
Compiled Models in Entity Framework Core
Using compiled models can reduce EF Core's startup time for applications that have large models, usually consisting of hundreds or thousands ...
Read more >
Compiled Models Quicken App Startups in Entity ...
The effort was proposed way back in March 2015 in a GitHub issue titled "Reduce EF Core application startup time via compiled models....
Read more >
EF Core 6.0 compiled models in software development
Compiled Models is a new EF Core 6 feature which vastly improves the startup times of DbContexts with large schemas. This would be...
Read more >
Investigating the performance benefits of EF Core 6.0 ...
Compiled Models is a new EF Core 6 feature which vastly improves the startup times of DbContexts with large schemas. This would be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found