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
While reading the codebase of Efcore I noticed a small inefficiency in a function used extensively throughout Efcore and I thought it was probably worth addressing.
In the above code, though the _indexerPropertyMap is used to ensure we get the same indexer for the same type, because we're calling type.FindIndexerProperty() we're not getting much benefit from it because the FindIndexerProperty function is run no matter if there is a key found or not.
The GetOrAdd function of the ConcurrentDictionary has an overload that accepts a Func<TKey, TValue> factory method specifically for this purpose.
If we instead change the function to the following:
While reading the codebase of Efcore I noticed a small inefficiency in a function used extensively throughout Efcore and I thought it was probably worth addressing.
Efcore/Metadata/RuntimeModel.cs -> Line 295
In the above code, though the
_indexerPropertyMap
is used to ensure we get the same indexer for the same type, because we're callingtype.FindIndexerProperty()
we're not getting much benefit from it because theFindIndexerProperty
function is run no matter if there is a key found or not.The
GetOrAdd
function of the ConcurrentDictionary has an overload that accepts aFunc<TKey, TValue>
factory method specifically for this purpose.If we instead change the function to the following:
We use the overload that accepts the
Func<TKey, TValue>
and only call the function if the key was not found in the map.The text was updated successfully, but these errors were encountered: