Skip to content

Conversation

@Ofekw
Copy link

@Ofekw Ofekw commented Nov 13, 2025

Description

This change fixes a JIT/IL memory growth issue caused by the Cosmos LINQ provider’s SubtreeEvaluator.EvaluateConstant method.
The previous implementation called Expression.Compile() each time an expression tree was evaluated, which emitted a new DynamicMethod and led to unbounded JIT code generation in long-running services.

The fix replaces:

Delegate function = lambda.Compile();

with

Delegate function = lambda.Compile(preferInterpretation: true);

to use the interpreted execution mode instead of generating new dynamic IL.
This change eliminates the unmanaged memory and JIT growth while preserving functional behavior.

No public APIs are changed, and no behavioral differences are expected aside from improved stability in memory-sensitive workloads.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Closing issues

Closes #5487 (JIT/IL growth due to SubtreeEvaluator.EvaluateConstant calling Expression.Compile() repeatedly)

Fix the evaluation of constant expressions by using preferInterpretation: true.

Because Expression.Compile() emits a new DynamicMethod each time, workloads that frequently build distinct expression trees experience unbounded JIT/IL growth and increasing memory usage in the process’ native RSS (anon_rx).
@Ofekw Ofekw changed the title Users/ofwitten/expression jit fix [Internal] LINQ: Fixes unbounded JIT/IL growth in SubtreeEvaluator by using interpreted expression compilation Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LINQ provider, the SDK continuously generates new JIT-compiled DynamicMethods (resulting in unmanaged memory growth)

2 participants