Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes projection expression resolution by reducing repeated reflection and allocation overhead in both the runtime resolver and the shared class-name generation utilities.
Changes:
- Add caching and allocation-reduction improvements to
ProjectionExpressionResolver(expression cache, type-name cache, reflection factory caching, non-LINQ parameter matching). - Optimize generated class-name construction in
ProjectionExpressionClassNameGenerator(single-pass namespace/type sanitization). - Adjust resolver service contract and related tests/utilities (
IProjectionExpressionResolversignature change;GetNestedTypePathreturns an array).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/EntityFrameworkCore.Projectables.Tests/Services/ProjectableExpressionReplacerTests.cs | Updates resolver stub and lambdas to match the updated resolver interface. |
| tests/EntityFrameworkCore.Projectables.Tests/Extensions/TypeExtensionTests.cs | Updates assertions to use array Length after GetNestedTypePath return type change. |
| src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs | Adds multiple caches and removes LINQ allocations in hot paths for expression resolution. |
| src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionClassNameGenerator.cs | Avoids intermediate string allocations when generating/sanitizing generated type names (shared with generator). |
| src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs | Passes the already-fetched ProjectableAttribute into the resolver. |
| src/EntityFrameworkCore.Projectables/Services/IProjectionExpressionResolver.cs | Updates resolver interface method signature (optional attribute parameter). |
| src/EntityFrameworkCore.Projectables/Extensions/TypeExtensions.cs | Changes GetNestedTypePath implementation and return type to a pre-sized array. |
src/EntityFrameworkCore.Projectables/Extensions/TypeExtensions.cs
Outdated
Show resolved
Hide resolved
src/EntityFrameworkCore.Projectables/Services/IProjectionExpressionResolver.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.
Benchmark :
Before :

After :

Registry resolution : 50 to 75 times faster, and no allocations anymore
Reflection resolution : 4 to 5 times faster, 4 to 5 times less allocations