-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve cache performance of MethodFinder.GetAllInstanceMethods #357
Conversation
Replace Dictionary to HashSet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find. :) Just a few observations from someone passing by.
{ | ||
uniqueInfos.Add(info, null); | ||
} | ||
uniqueInfos.Add(info); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tangdf did you see the code review comments?
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.