Improve cache performance of MethodFinder.GetAllInstanceMethods#357
Improve cache performance of MethodFinder.GetAllInstanceMethods#357jonorossi merged 7 commits intocastleproject:masterfrom tangdf:master
Conversation
Replace Dictionary to HashSet
stakx
left a comment
There was a problem hiding this comment.
Nice find. :) Just a few observations from someone passing by.
| uniqueInfos.Add(info, null); | ||
| } | ||
| uniqueInfos.Add(info); | ||
| } |
There was a problem hiding this comment.
This foreach loop probably isn't needed at all when using the HashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer) ctor instead.
There was a problem hiding this comment.
Seeing the call site it looks like this method could be removed and the call site just replaced with:
type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Distinct(MethodSignatureComparer.Instance)
.ToArray();
This code is cruddy because it would have been written pre-.NET 3.5 so before LINQ and HashSet.
| @@ -78,17 +78,14 @@ private static MethodInfo[] MakeFilteredCopy(MethodInfo[] methodsInCache, Bindin | |||
|
|
|||
| private static object RemoveDuplicates(MethodInfo[] infos) | |||
There was a problem hiding this comment.
(Unrelated to this change, and I haven't looked at the call sites... but I wonder why this method's declared return type is object, instead of MethodInfo[]? Do call sites have to cast the return value back to MethodInfo[]?)
There was a problem hiding this comment.
They get stored into a field Dictionary<Type, object> cachedMethodInfosByType, so yes this field should be updated too since there is only one call site of this private method.
`KeyValuePair<Key, Value>` not implemented interface `IEquatable<>`.
Replace KeyValuePair<MethodInfo, Type> to custom struct
|
@tangdf you've merged your cache key changes into this branch (because you used your master) which updated this pull request, so it now conflicts. |
|
I'm so sorry,I ignored the comments. |
|
Don’t worry @tangdf we have all been there. Keep it going! ;) |
|
Thanks @tangdf, merged. |
No description provided.