AutoLOD has a performance bottleneck on assembly reload due to the following call hierarchy
AutoLOD..ctor() (Called because it has [InitializeOnLoad])
AutoLOD.UpdateDependencies()
AutoLOD.get_meshSimplifierType()
AutoLOD.get_meshSimplifiers()
ObjectUtils.GetImplementationsOfInterface()
ObjectUtils.GetAssignableTypes()
From there on, AutoLOD iterates over every type of every loaded assembly, which is very time consuming.
This is precisely why Unity introduced the TypeCache API. With it, we can remove the ForEachType and ForEachAssembly routines in AutoLOD (used in 3 places), thus greatly increasing its startup performance.
Here's my reimplementation of ObjectUtils.GetAssignableTypes(), for example:
static IEnumerable<Type> GetAssignableTypes(Type type, Func<Type, bool> predicate = null)
{
var list = new List<Type>();
foreach (var t in TypeCache.GetTypesDerivedFrom(type))
{
if (!t.IsInterface && !t.IsAbstract && (predicate == null || predicate(t))
&& t.GetCustomAttribute<HideInInspector>() == null)
list.Add(t);
};
return list;
}
AutoLOD has a performance bottleneck on assembly reload due to the following call hierarchy
From there on, AutoLOD iterates over every type of every loaded assembly, which is very time consuming.
This is precisely why Unity introduced the TypeCache API. With it, we can remove the ForEachType and ForEachAssembly routines in AutoLOD (used in 3 places), thus greatly increasing its startup performance.
Here's my reimplementation of ObjectUtils.GetAssignableTypes(), for example: