Skip to content

Commit

Permalink
Fix to #35208 - Query/Perf: don't compile liftable constant resolvers…
Browse files Browse the repository at this point in the history
… in interpretation mode when the resolver itself contains a lambda

In EF9 we changed the way we generate shapers in preparation for AOT scenarios. We no longer can embed arbitrary objects into the shaper, instead we need to provide a way to construct that object in code (using LiftableConstant mechanism), or simulate the functionality it used to provide.
At the end of our processing, we find all liftable constants and for the non-AOT case we compile their resolver lambdas and invoke the result with liftable context object to produce the resulting constant object we initially wanted. (in AOT case we generate code from the resolver lambda).
Problem is that we are compiling the resolver lambda in the interpretation mode - if the final product is itself a delegate, that delegate will itself be in the interpreter mode and therefore less efficient.

Fix is to use regular compilation rather than interpretation.

Fixes #35208

This is part of a fix for a larger perf issue: #35053
  • Loading branch information
maumar committed Nov 26, 2024
1 parent 919a645 commit bb404fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ protected override ConstantExpression InlineConstant(LiftableConstantExpression
if (liftableConstant.ResolverExpression is Expression<Func<RelationalMaterializerLiftableConstantContext, object>>
resolverExpression)
{
var resolver = resolverExpression.Compile(preferInterpretation: true);
// TODO: deep dive into this - see issue #35210
var resolver = resolverExpression.Compile(preferInterpretation: false);
var value = resolver(_relationalMaterializerLiftableConstantContext);
return Expression.Constant(value, liftableConstant.Type);
}
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Query/LiftableConstantProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ protected virtual ConstantExpression InlineConstant(LiftableConstantExpression l
// Make sure there aren't any problematic un-lifted constants within the resolver expression.
_unsupportedConstantChecker.Check(resolverExpression);

var resolver = resolverExpression.Compile(preferInterpretation: true);
// TODO: deep dive into this - see issue #35210
var resolver = resolverExpression.Compile(preferInterpretation: false);
var value = resolver(_materializerLiftableConstantContext);

return Expression.Constant(value, liftableConstant.Type);
Expand Down

0 comments on commit bb404fb

Please # to comment.