jacobdufault / fullinspector

Full Inspector supercharges Unity's inspector
MIT License
111 stars 27 forks source link

Inspector GUI very slow when showing lots of SharedInstances #184

Closed hymerman closed 7 years ago

hymerman commented 7 years ago

The TryEnsureScript call inside fiSharedInstancePropertyEditor calls fiSharedInstanceUtility.GetSerializableType, which I'm finding is extremely slow, mostly because of the Assembly.GetTypesWithoutException call which allocates a lot of memory, and iterating through the many, many types which costs a lot of CPU time.

Is there some way to cache the results of e.g. fiRuntimeReflectionUtility.AllSimpleTypesDerivingFrom? I imagine the cache would need to be regenerated on any assembly reload but I'm not sure how to go about doing that. Any ideas?

jacobdufault commented 7 years ago

Yep, caching this should be reasonable. Rename AllSimpleTypesDerivingFrom to AllSimpleTypesDerivingFromInternal.

Then the cache is just

static Dictionary<Type, IEnumerable<Type>> cache = new Dictionary<Type, IEnumerable<Type>>();

public IEnumerable<Type> AllSimpleTypesDerivingFrom(Type t) {
    IEnumerable<Type> result;
    if (!cache.TryGetValue(t, out result)) {
        result = AllSimpleTypesDerivingFromInternal(t);
        cache[t] = result;
    }
    return result;
}
jacobdufault commented 7 years ago

I'll try to get to this in a few days, but I'd be happy to accept a pull request :)

hymerman commented 7 years ago

Thanks - I've done something similar to this locally and it's a great speed improvement, but I still don't know what happens with reloading assemblies - if you think it's ok though, that's good enough for me :) I'll cobble a PR together if I get time (and will say I'm doing so here so you don't waste time doing it yourself!).

hymerman commented 7 years ago

I've done this and tweaked it a bit; I'll submit a PR later