Project Validator performance degrades after each run

Issue #712 resolved
Yaroslav Kovtun created an issue

Each run of Project Validator takes longer time for me with the same assets. Here is an example with 10 TextMeshPro TMP_FontAssets:

  1. 10 seconds
  2. 16 seconds
  3. 26 seconds
  4. 37 seconds

I have investigated this using the profiler, and found one fix that improves performance, but the problem in general still remains.

So, one method in particular that takes a lot of time in the profiler is Sirenix.OdinInspector.Editor.UnityPropertyEmitter.DestroyMarkedObjects:

private static void DestroyMarkedObjects()
        {
            lock (MarkedForDestruction_LOCK)
            {
                for (int i = 0; i < MarkedForDestruction.Count; i++)
                {
                    var obj = MarkedForDestruction[i];

                    if (obj != null)
                    {
                        //Debug.Log("Actually destroying " + obj.name);
                        UnityEngine.Object.DestroyImmediate(obj);
                    }
                }
            }
        }

The obj != null comparison is actually pretty expensive if obj is destroyed. This method checks the same destroyed objects again and again during the scan. So clearing the MarkedForDestruction list at the end of this method improves performace by 15-30%, the more assets the more improvement.

Unfortunately, this does not fix the problem in general, since every subsequent scan still takes longer.

Odin Inspector and Project validator 3.0.1.0, Unity 2020.1.9f1, Windows 10.

Comments (4)

  1. Tor Esa Vestergaard

    Not clearing the list is an embarrassing miss! 😃 Thanks for the headsup, this would happen a lot when we need to draw with legacy Unity drawer compatibility for non-Unity-serialized data (the case where we need to emit Unity object types and use them as wrapper instances for “fake” Unity properties to draw), so it’s at least not a super common case. I will look into this.

  2. Log in to comment