efcore
efcore copied to clipboard
Fix for #34117, Improve Hash Code Distribution for RelationalCommandCache Keys
This PR addresses a performance issue in the RelationalCommandCache class where the CommandCacheKey struct uses a hard-coded GetHashCode implementation that returns 0. This implementation leads to all instances being placed in the same bucket within the MemoryCache's internal HashSet, causing linear search times and negating the performance benefits of the hash-based collection.
See Issue https://github.com/dotnet/efcore/issues/34117
Changes
-
Modified the GetHashCode implementation in the CommandCacheKey struct to use RuntimeHelpers.GetHashCode(_queryExpression).
-
Ensured that the new implementation maintains the contract with the overridden Equals method, which first checks for reference equality.