Skip to content

Evaluate captured values without compiling; cache row readers by shape - #883

Merged
Thorium merged 5 commits into
fsprojects:masterfrom
Thorium:query-compile-cost
Nov 22, 2026
Merged

Thorium merged 5 commits into
fsprojects:masterfrom
Thorium:query-compile-cost

Conversation

@Thorium

@Thorium Thorium commented Nov 19, 2026

Copy link
Copy Markdown
Member
  • Patterns.evaluateExpression reads a query's one-off values (constants, members, method calls on captured values, conversions, quotes) by reflection and interprets the rest, in place of Expression.Lambda(e).Compile().
  • QueryExpression.CompiledLambdas compiles a row reader once per shape and binds each run's constants into it. Not used where the runtime interprets lambdas (IsDynamicCodeSupported false).
  • Exceptions from a captured value are raised unwrapped.

- Patterns.evaluateExpression reads a query's one-off values (constants, members, method calls on captured values, conversions, quotes) by reflection and interprets the rest, in place of Expression.Lambda(e).Compile().
- QueryExpression.CompiledLambdas compiles a row reader once per shape and binds each run's constants into it. Not used where the runtime interprets lambdas (IsDynamicCodeSupported false).
- Exceptions from a captured value are raised unwrapped.
@Thorium
Thorium requested a balanced review from Copilot November 19, 2026 13:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical cache-key defects remain: member mappings in NewExpression projections and declared lambda parameter order are omitted or misrepresented, allowing distinct expressions to reuse the wrong compiled factory.

2 open issues

Review effort: Lite

# Conflicts:
#	docs/RELEASE_NOTES.md
#	tests/SqlProvider.Tests/SqlProvider.Tests.fsproj

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical portability issue remains because the non-dynamic-code path still invokes the default lambda compiler, which can fail in NativeAOT or interpreter-only deployments.

1 open issue
2 resolved since last review

Review effort: Lite


/// The lambda's delegate, from the factory compiled for its shape; a lambda the shape doesn't describe is compiled alone.
let internal compile (lambda: LambdaExpression) : Delegate =
if not compilesToIL then lambda.Compile()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On modern .NET the plain Compile() already chooses the interpreter itself when dynamic code is not supported.

@Thorium
Thorium merged commit 25b1caf into fsprojects:master Nov 22, 2026
3 checks passed
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.

2 participants