Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DuplicateEditorMesh performance issue
#4
Alright, I found a way to drastically reduce that Awake time, but there is still more I can do. Allow me to explain:

In my extreme test scene, it initally took 14 seconds to run all the awake methods. Only 2.5s of these 14 where spend on FindObjectsOfType. The remaining was used in other methods, a lots of it used in references comparison (== and != operators). This is due to how unity handles the == operator: it does not only compare references, but checks also if the associated Objects are destroyed or not, and if the instance ids match or not. I managed to reduce the need to call those operators, bringing the 14s down to 7s (The modified code is at the end of the post). That's good, but more can be done.
 
The solutions you suggested were focused on the FindObjectsOfType, and assumptions I need to verify (such as duplication happens only because of Paste and Duplicate events). If those assumptions are valid, your solution will help with the issue, but not solve the whole problem. I am thinking of another solution, based on using a HashMap to keep track of what meshes exist, but I need to dig deep into the DuplicateEditorMesh usages and raison d'être Smile to make sure I am not introducing regressions. I will delay this work for a later date. For now, I hope that the changes bellow will make the performance acceptable for your use case.


Code:
    public MeshFilter Filter
        {
            get
            {
                if (ReferenceEquals(mFilter, null))
                    mFilter = GetComponent<MeshFilter>();
                return mFilter;
            }
        }

        protected virtual void Awake()
        {
            if (!Application.isPlaying)
            {
                MeshFilter meshFilter = Filter;
                Mesh meshFilterSharedMesh = meshFilter.sharedMesh;
                if (meshFilter && meshFilterSharedMesh != null)
                {
                    DuplicateEditorMesh[] otherWatchdogs = GameObject.FindObjectsOfType<DuplicateEditorMesh>();
                    foreach (DuplicateEditorMesh dog in otherWatchdogs)
                    {
                        if (ReferenceEquals(dog, this) == false)
                        {
                            MeshFilter otherMF = dog.Filter;
                            if (otherMF != null)
                            {
                                Mesh otherMfSharedMesh = otherMF.sharedMesh;
                                if (ReferenceEquals(otherMfSharedMesh, meshFilterSharedMesh))
                                {
                                    Mesh m = new Mesh();
                                    m.name = otherMfSharedMesh.name;
                                    meshFilter.mesh = m;
                                }
                            }
                        }
                    }
                }
            }
        }
   


Feel free to ask me more questions about this subject or any other one.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Messages In This Thread
RE: DuplicateEditorMesh performance issue - by _Aka_ - 01-17-2022, 12:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasterized Path Range issue proton 3 15 Yesterday, 09:26 AM
Last Post: proton
  I want to improve the performance of Variable Mix Shapes yanke 7 8 07-27-2023, 09:15 PM
Last Post: _Aka_
  Rotation issue with generator nicolaj.h.andersen@gmail.com 1 15 04-14-2023, 11:58 AM
Last Post: _Aka_
  BuildVolumeMesh issue tairoark 40 95 11-25-2022, 07:57 AM
Last Post: _Aka_

Forum Jump: