Skip to content

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

Open
Thorium wants to merge 1 commit into
fsprojects:masterfrom
Thorium:query-compile-cost
Open

Thorium wants to merge 1 commit 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

Comment on lines +46 to +52
let parameters = Dictionary<ParameterExpression, int>(HashIdentity.Reference)
let positionOf (p: ParameterExpression) =
match parameters.TryGetValue p with
| true, i -> i
| false, _ ->
parameters.Add(p, parameters.Count)
parameters.Count - 1

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.

Not a collision. ExpressionVisitor visits a lambda’s parameter list after its body, so the declaration order is in the key: a - b gives body 0 1, declarations 0 1; b - a gives body 0 1, declarations 1 0. The test lambdas of other shapes are not mixed up asserts 7 and -7 for this case and passes in CI.

Comment on lines +92 to +95
| :? NewExpression as n ->
add n.Constructor
add (box n.Arguments.Count)
true

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.

Members doesn’t change the compiled delegate: the compiler emits newobj from the constructor and the arguments only. Two NewExpressions with one constructor and different member lists compile to the same code, so sharing a factory is correct.

This branch has not been deployed

No deployments
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