dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.71k stars 3.17k forks source link

Query: Evaluate compiled delegates for perf opportunity #24799

Open smitpatel opened 3 years ago

smitpatel commented 3 years ago

Specifically try to get the shaper lambda before it is compiled out and generated IL for it after compilation. This would identify if compiler is missing certain optimizations due to being generated out of an expression tree and we can generate a better tree.

Query scenario to consider

P.S. Last I heard @roji volunteered for this. :trollface:

roji commented 3 years ago

"Volunteer" has its own meaning in the context of the EF Core team :rofl:

thargol1 commented 3 years ago

Could someone provide more details? I know lambda's, I have some experience with generating IL and expression trees. But the way this issue is posted only and experienced EF-core insider can work on it.

What is a shaper? Where is the current source code and the unit tests? Examples of non optimal generated code and preferred generated code? Can the problem be researched in isolated code for faster compile times?

Is there a maximum run time for the optimizer? I think this code should run in less than 1ms?

I have time, but I really don't know if I'm qualified for this.

smitpatel commented 3 years ago

https://github.com/dotnet/efcore/blob/7482ed720f282ea32f6189888bc269dbf4689ecc/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.cs#L67-L68

This is where EF Core generates a shaperLambda (for relational providers, other providers have similar code for theirs), which gets compiled into a deleted and passed to querying enumerable to shape results out of the server side query object (DbDataReader for relational providers).

Rest of the questions are invalid.