Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a runtime optimization to ProjectableExpressionReplacer by avoiding Expression.Compile() when attempting to inline captured IQueryable closures, and introduces new functional tests/snapshots to validate query output for several closure-capture scenarios.
Changes:
- Replace closure-member evaluation in
ProjectableExpressionReplacer.VisitMemberwith reflection-based access and add several static caches for common reflection lookups. - Add
ClosureMemberAccessTestsfunctional test coverage plus Verify snapshots for net8/net9/net10 SQL output.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs | Reworks closure-member handling (reflection vs compile) and adds per-Type caches for performance. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.cs | Adds functional tests intended to validate closure member access/inlining behavior. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIntField_UsedInProjectableMethod.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIntField_UsedInProjectableMethod.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIntField_UsedInProjectableMethod.DotNet10_0.verified.txt | Snapshot for net10 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedStringField_UsedInProjectableMethod.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedStringField_UsedInProjectableMethod.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedStringField_UsedInProjectableMethod.DotNet10_0.verified.txt | Snapshot for net10 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMultipleIntFields_UsedInProjectableMethod.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMultipleIntFields_UsedInProjectableMethod.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMultipleIntFields_UsedInProjectableMethod.DotNet10_0.verified.txt | Snapshot for net10 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaAny.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaAny.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaAny.DotNet10_0.verified.txt | Snapshot for net10 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaCount.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaCount.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedIQueryableField_SubqueryInlinedViaCount.DotNet10_0.verified.txt | Snapshot for net10 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMixedFields_IntAndIQueryable_BothResolvedCorrectly.verified.txt | Snapshot for net8 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMixedFields_IntAndIQueryable_BothResolvedCorrectly.DotNet9_0.verified.txt | Snapshot for net9 query output. |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.CapturedMixedFields_IntAndIQueryable_BothResolvedCorrectly.DotNet10_0.verified.txt | Snapshot for net10 query output. |
tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.cs
Show resolved
Hide resolved
tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.cs
Show resolved
Hide resolved
tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.cs
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs
Outdated
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs
Outdated
Show resolved
Hide resolved
tests/EntityFrameworkCore.Projectables.FunctionalTests/ClosureMemberAccessTests.cs
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ClosureCaptureBenchmark
Before :
After :
Speed gain is huge ! CompatibilityMode Full does not add as much overhead as before.
Value closures : 118µs to 1.27µs overhead
Queryable closures : 100%s to 2.66µs overhead