You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We found in our application that due to a large number of generated items RelationalCommandCache reached capacity the system would need to do linear searches through MemoryCache's ConcurrentDictionary of CommandCacheKeys due to them all being in the same bucket since there is a hard-coded GetHashCode() of 0. This avoids the advantages of ConcurrentDictionary's O(1) lookup time.
I thought that a simple improvement would be to use RuntimeHelpers.GetHashCode(_queryExpression) instead of 0. This would improve the distribution of buckets in the HashSet while maintaining the contract with the overridden Equals while avoiding any hashcode calculation explosion that might happen if we considered the _parameterValues that are also used in Equals or if an overridden Expression GetHashCode looked at the items in the Expression. as mentioned in #19859.
Since reference equality is the first thing checking in Equals this will be consistent to uniquely find a CommandCacheKey
The text was updated successfully, but these errors were encountered:
We found in our application that due to a large number of generated items
RelationalCommandCache
reached capacity the system would need to do linear searches through MemoryCache'sConcurrentDictionary
ofCommandCacheKey
s due to them all being in the same bucket since there is a hard-codedGetHashCode()
of0
. This avoids the advantages ofConcurrentDictionary
's O(1) lookup time.I thought that a simple improvement would be to use
RuntimeHelpers.GetHashCode(_queryExpression)
instead of0
. This would improve the distribution of buckets in the HashSet while maintaining the contract with the overriddenEquals
while avoiding any hashcode calculation explosion that might happen if we considered the_parameterValues
that are also used inEquals
or if an overridden ExpressionGetHashCode
looked at the items in the Expression. as mentioned in #19859.Since reference equality is the first thing checking in
Equals
this will be consistent to uniquely find aCommandCacheKey
The text was updated successfully, but these errors were encountered: