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
Hey

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.
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
#7
A fix for this is now available in version 8.5.0. Thanks for your patience.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 0 0 1 hour ago
Last Post: ShiroeYamamoto
Exclamation Extending Curvy Generator for Advanced Lofting - Feasibility Check amutp 2 4 Yesterday, 07:25 AM
Last Post: amutp
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 0 6 Yesterday, 03:23 AM
Last Post: _Aka_
  Using Unity's SplineContainer in Curvy Splines dlees9191 3 15 02-26-2024, 09:49 AM
Last Post: _Aka_

Forum Jump: