Skip to content

Commit 1319ed4

Browse files
authored
Fix to #35208 - Query/Perf: don't compile liftable constant resolvers in interpretation mode when the resolver itself contains a lambda (#35209)
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
1 parent 919a645 commit 1319ed4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/EFCore.Relational/Query/RelationalLiftableConstantProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected override ConstantExpression InlineConstant(LiftableConstantExpression
3636
if (liftableConstant.ResolverExpression is Expression<Func<RelationalMaterializerLiftableConstantContext, object>>
3737
resolverExpression)
3838
{
39-
var resolver = resolverExpression.Compile(preferInterpretation: true);
39+
// TODO: deep dive into this - see issue #35210
40+
var resolver = resolverExpression.Compile(preferInterpretation: false);
4041
var value = resolver(_relationalMaterializerLiftableConstantContext);
4142
return Expression.Constant(value, liftableConstant.Type);
4243
}

src/EFCore/Query/LiftableConstantProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ protected virtual ConstantExpression InlineConstant(LiftableConstantExpression l
198198
// Make sure there aren't any problematic un-lifted constants within the resolver expression.
199199
_unsupportedConstantChecker.Check(resolverExpression);
200200

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

204205
return Expression.Constant(value, liftableConstant.Type);

0 commit comments

Comments
 (0)