[rc2] Optimize FindIndexerPropertyInfo methods to avoid unnecessary reflection calls#36648
[rc2] Optimize FindIndexerPropertyInfo methods to avoid unnecessary reflection calls#36648AndriySvyryd merged 2 commits intorelease/10.0from
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
|
@copilot Rewrite the summary using this template: |
... Updated the PR description to follow the requested template: Fixes #34823 Description Customer impact How found Regression Testing Risk |
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.