-
Notifications
You must be signed in to change notification settings - Fork 391
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
Cache HasCustomAttribute #5269
base: master
Are you sure you want to change the base?
Cache HasCustomAttribute #5269
Conversation
Makes debug a lot faster. No idea if static semaphoreslims are bad but my game didn't explodeTM.
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.
It would be way better if usages of this function were cached instead, but I guess I'll allow it...
|
||
namespace Robust.Shared.Utility | ||
{ | ||
public static class TypeHelpers | ||
{ | ||
private static SemaphoreSlim _hasSlim = new(1); | ||
private static Dictionary<MemberInfo, Dictionary<Type, bool>> _hasAttribute = new(); |
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.
private static Dictionary<MemberInfo, Dictionary<Type, bool>> _hasAttribute = new(); | |
private static readonly Dictionary<MemberInfo, Dictionary<Type, bool>> _hasAttribute = new(); |
@@ -183,7 +188,18 @@ public static bool IsBackingField(this MemberInfo memberInfo) | |||
|
|||
public static bool HasCustomAttribute<T>(this MemberInfo memberInfo) where T : Attribute | |||
{ | |||
return memberInfo.GetCustomAttribute<T>() != null; | |||
using (_hasSlim.WaitGuard()) |
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.
Just use lock()
on the dictionary instead.
If you want me to do it I can do it, it's primarily dirty and addcomp calls afaik. |
Makes debug a lot faster. No idea if static semaphoreslims are bad but my game didn't explodeTM.
Resolves #5268