Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ScanConnections() causes heavy load in play mode, even with all Curvy objects removed
#1
[font="JetBrains Mono", monospace]Hey[/font]

[font="JetBrains Mono", monospace]In our project we're finding that Curvy eats a lot of cycles running ScanConnections in CurvyProject.cs, even if we don't have any curvy splines loaded, or the curvyglobal object, or the toolbar active. How can we stop that from happening? It's killing our edit time performance.[/font]
Reply
#2
Hi
That method is used to build the list of game objects with connections for editor UI purpose (to add a gizmo next to them). So if you deactivate it, besides not having that gizmo anymore, nothing will break.
You can deactivate the automatic call to that method by going to CurvyProject.cs, and comment the following line
EditorApplication.hierarchyChanged += ScanConnections
In order for me to enhance the performance of that method, can you please help me by providing me one or more of the following:
- A reproduction case
- A screenshot of the profiler window showing the call to that method
- The number of game objects you have in your scene, the number of control points, and the number of connections.

Let me know if my work around didn't work
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
#3
Thanks. The problem is produced because we have a large project with tens of thousands of objects in the scene (which makes a repro case hard to make). There are no curvy objects and no connections loaded, but this gets called all the time in edit and play mode even though we aren't using any curvy functions in play mode at all (we just use it as a nice tool for making static meshes)

I'll try to get you a profiler screenshot.

/edit basically you can't be calling FindGameObjectsOfType every frame, either at edit or run time, because in large scenes it's just going to always tank performance.
Reply
#4
Thanks. No need for the profiler screenshot if it will take from your time. Now that I know that you have tens of thousands of objects, I have what I need to be able to enhance the situation. I am adding this to my todo list
Thanks for reporting the issue.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Hi again.

1- After digging in this subject, I see that ScanConnections is not set to be executed every frame. It is supposed to execute only when the hierarchy changes. Does your hierarchy change every frame?

2- I tested with 20k cubes, and ScanConnections did not show any significant CPU usage. Maybe it is because your game objects are way more complex?

3- Here is an optimization to ScanConnections:
replace
CurvyConnection[] o = GameObject.FindObjectsOfType<CurvyConnection>();
with
CurvyConnection[] o = CurvyGlobalManager.Instance.GetComponentsInChildren<CurvyConnection>();
Since I couldn't reproduce the issue, I wasn't able to test how efficient this optimization is, but it is theoretically efficient. Can you please apply it on your project and tell me what was the result? Thanks
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
(07-23-2021, 12:28 PM)_Aka_ Wrote: 1- After digging in this subject, I see that ScanConnections  is not set to be executed every frame. It is supposed to execute only when the hierarchy changes. Does your hierarchy change every frame?

Yes, because we're loading and unloading assets dynamically (the level is large). Right now we're using SECTR_Stream, but it's just additively loading scenes and terrains. But at edit time, obviously we're only changing the hierarchy every time we click the mouse, so not quite every frame.

(07-23-2021, 12:28 PM)_Aka_ Wrote:
2- I tested with 20k cubes, and ScanConnections did not show any significant CPU usage. Maybe it is because your game objects are way more complex?

Yes, I'd say that's right. But our use case would be typical of a modern open-world game. We try to keep the hierarchy as flat as possible but still any kind of FindAll() is going to take several milliseconds.

(07-23-2021, 12:28 PM)_Aka_ Wrote:
3- Here is an optimization to ScanConnections:
replace
CurvyConnection[] o = GameObject.FindObjectsOfType<CurvyConnection>();
with
CurvyConnection[] o = CurvyGlobalManager.Instance.GetComponentsInChildren<CurvyConnection>();
Since I couldn't reproduce the issue, I wasn't able to test how efficient this optimization is, but it is theoretically efficient. Can you please apply it on your project and tell me what was the result? Thanks

Sure, we'll give it a try.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy not appearing in Unity 2019.2.14f1 bmacdonald1986 5 3,017 11-25-2021, 10:52 AM
Last Post: _Aka_
  Is Curvy splines appropriate to build city streets? atantoine 3 176 11-17-2021, 12:03 PM
Last Post: _Aka_
Information Curvy 7.1.6 is live _Aka_ 0 132 10-29-2021, 01:51 PM
Last Post: _Aka_
  GameObjects that move along the path of Curvy Splines will protrude. yanke 5 337 10-26-2021, 09:59 AM
Last Post: _Aka_

Forum Jump: