Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Re-add caching to user type lookups
Browse files Browse the repository at this point in the history
- Improves compile performance on larger scripts a little bit
  • Loading branch information
MerlinVR committed Dec 10, 2020
1 parent af0b795 commit b52c40c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Assets/UdonSharp/Editor/UdonSharpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,18 @@ internal static System.Type RemapBaseType(System.Type type)

return type;
}

// Doesn't work in a multi threaded context, todo: consider making this a concurrent collection or making one for each thread.
//private static Dictionary<System.Type, System.Type> userTypeToUdonTypeCache = new Dictionary<System.Type, System.Type>();
[ThreadStatic]
private static Dictionary<System.Type, System.Type> userTypeToUdonTypeCache;

public static System.Type UserTypeToUdonType(System.Type type)
{
if (userTypeToUdonTypeCache == null)
userTypeToUdonTypeCache = new Dictionary<Type, Type>();

if (userTypeToUdonTypeCache.TryGetValue(type, out System.Type foundType))
return foundType;

System.Type udonType = null;

if (IsUserDefinedType(type))
Expand All @@ -575,6 +581,8 @@ public static System.Type UserTypeToUdonType(System.Type type)
udonType = type;

udonType = RemapBaseType(udonType);

userTypeToUdonTypeCache.Add(type, udonType);

return udonType;
}
Expand Down

0 comments on commit b52c40c

Please sign in to comment.