Query: Evaluate compiled delegates for perf opportunity
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
- Simple entity projection
- Anonymous type projection
- Include a reference
- Include a collection
P.S. Last I heard @roji volunteered for this. :trollface:
"Volunteer" has its own meaning in the context of the EF Core team :rofl:
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.
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).
- Shaper is the delegate which runs on DbDataReader and generates user result type in the given enumerable query.
- Source code is linked above.
- There are only functional tests hitting this code path since generation of shaper (and getting dataset from server) are tightly coupled with LINQ query written. Unit tests are either trivial or doesn't verify functionality.
- There is no example of optimized/preferred code. This issue is about getting shaper lambda for various different kind of queries and see the compiled delegate generated (IL-wise) and see if it is unoptimized code due to the way expression tree for shaper being constructed.
Rest of the questions are invalid.
This would be replaced by https://github.com/dotnet/efcore/issues/34445