Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 25, 2025

Fixes #34823

Description
Optimizes FindIndexerPropertyInfo methods in both RuntimeModel.cs and Model.cs to avoid unnecessary reflection calls. The current implementation calls the expensive FindIndexerProperty() method on every GetOrAdd call, even when the key already exists in the cache. Changed to use the factory overload of GetOrAdd with a static lambda that only executes when the key is not found.

Customer impact
Applications that repeatedly process the same entity types will see improved performance, as cached lookups now avoid expensive reflection operations. This is particularly beneficial in high-throughput scenarios where the same types are processed frequently. No breaking changes - existing applications continue to work without modification.

How found
Customer reported via GitHub issue #34823. The issue was identified by a contributor while reading the EF Core codebase.

Regression
Not a regression - this is an existing inefficiency that has been present in the codebase.

Testing
All existing tests continue to pass. The change is functionally equivalent to the previous implementation but with better performance characteristics for cached lookups.

Risk
Low. The change is minimal (only 2 lines modified) and preserves the exact same public API and behavior. The optimization uses well-established .NET patterns and only affects the internal implementation detail of how the cache factory is invoked.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Correct small inefficiency in private internal function in EFCore - FindIndexerPropertyInfo Optimize FindIndexerPropertyInfo methods to avoid unnecessary reflection calls Aug 25, 2025
Copilot AI requested a review from AndriySvyryd August 25, 2025 23:08
@AndriySvyryd
Copy link
Member

@copilot Rewrite the summary using this template:

Fixes #{number} **Description** {issue description} **Customer impact** {How does this issue affect customer's app? Are there workaround?} **How found** {Was it customer reported or found during verification? How many customers are affected?} **Regression** {Is it a regression from a released version? Which one?} **Testing** {How the changes were tested} **Risk** {Low/Medium/High, argument why} 
Copy link
Contributor Author

Copilot AI commented Aug 25, 2025

@copilot Rewrite the summary using this template:

...

Updated the PR description to follow the requested template:

Fixes #34823

Description
Optimizes FindIndexerPropertyInfo methods in both RuntimeModel.cs and Model.cs to avoid unnecessary reflection calls. The current implementation calls the expensive FindIndexerProperty() method on every GetOrAdd call, even when the key already exists in the cache. Changed to use the factory overload of GetOrAdd with a static lambda that only executes when the key is not found.

Customer impact
Applications that repeatedly process the same entity types will see improved performance, as cached lookups now avoid expensive reflection operations. This is particularly beneficial in high-throughput scenarios where the same types are processed frequently. No breaking changes - existing applications continue to work without modification.

How found
Customer reported via GitHub issue #34823. The issue was identified by a contributor while reading the EF Core codebase.

Regression
Not a regression - this is an existing inefficiency that has been present in the codebase.

Testing
All existing tests continue to pass. The change is functionally equivalent to the previous implementation but with better performance characteristics for cached lookups.

Risk
Low. The change is minimal (only 2 lines modified) and preserves the exact same public API and behavior. The optimization uses well-established .NET patterns and only affects the internal implementation detail of how the cache factory is invoked.

Copilot AI requested a review from AndriySvyryd August 25, 2025 23:16
@AndriySvyryd AndriySvyryd requested a review from artl93 August 25, 2025 23:18
@AndriySvyryd AndriySvyryd marked this pull request as ready for review August 25, 2025 23:21
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner August 25, 2025 23:21
@AndriySvyryd AndriySvyryd changed the title Optimize FindIndexerPropertyInfo methods to avoid unnecessary reflection calls [rc2] Optimize FindIndexerPropertyInfo methods to avoid unnecessary reflection calls Aug 25, 2025
@AndriySvyryd AndriySvyryd merged commit 3aca835 into release/10.0 Aug 26, 2025
8 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-34823 branch August 26, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 participants