Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CurvySpline.Update() sorta expensive
#1
I have a lot of splines, I don't ever move them, they are static. Why do they need to Update ? 

Can there be a "No Update" mode ? I tried adding one, but then querying spline info does not 
seem to work anymore.

I've added : 
            if (m_UpdateIn == CurvyUpdateMethod.NoUpdate)
                doUpdate();


to the OnEnable call for CurvySpline.cs :  

that seems to make it work, although would be better if it didn't have to refresh the spline OnEnable, just use the data from Editor, I'm going to keep on modding it. Is there a better way to just generate the spline and never update ?


OK I think this does it: 

moved the code all the way to the top of the OnEnable() function:

            if (m_UpdateIn == CurvyUpdateMethod.NoUpdate)
            {
                mIsInitialized = true;
                doUpdate();
                return;
            }


This effectively makes the splines almost zero cost all the time. Not sure what effect it might have in the Editor, but
you can switch it back to Update when editing the splines and switch it back to NoUpdate once you are done. 

Anyway I suggest this small change, should be added to next version !  Big Grin
Reply
#2
Ok, you're not the first one mentioning expensive Update() calls and while I'm still wondering about this, we need to discuss this in depth, I guess. Perhaps there's a bug or something else going wrong...

I made a quick test on my netbook I'm currently on. Fresh scene, created 10 different splines and duplicated them several times, giving me 120 splines. Default settings, nothing changed in the inspector. A quick profile gave me ~2ms for 120 Update() calls. That's quite much, but it's because of the default setting "Check Transforms", meaning all transforms of all CPs of all splines will get checked for updates each frame. If I disable that option, those 120 calls to Update() run at 0.2ms.

So, I really don't see the point in adding compile flags etc. to remove Update() calls or introduce other optimizations. Either you and others have several thousand splines floating around and/or are running on extremly slow hardware - OR - your profiling looks completly different and something makes that calls extremly expensive. Perhaps a certain setup, some added controllers or custom scripts or a bug that doesn't show up on my side while testing.

Don't get me wrong, I'd like to take that serious and investigate this. Many users have reported this, so there must be something going on. I just don't see it. Would you mind running the profiler and give me some details, perhaps you'd like to send me an example scene to jake<at>fluffyunderware<dot>com.
Reply
#3
(04-27-2016, 06:54 PM)Jake Wrote: Ok, you're not the first one mentioning expensive Update() calls and while I'm still wondering about this, we need to discuss this in depth, I guess. Perhaps there's a bug or something else going wrong...

I made a quick test on my netbook I'm currently on. Fresh scene, created 10 different splines and duplicated them several times, giving me 120 splines. Default settings, nothing changed in the inspector. A quick profile gave me ~2ms for 120 Update() calls. That's quite much, but it's because of the default setting "Check Transforms", meaning all transforms of all CPs of all splines will get checked for updates each frame. If I disable that option, those 120 calls to Update() run at 0.2ms.

So, I really don't see the point in adding compile flags etc. to remove Update() calls or introduce other optimizations. Either you and others have several thousand splines floating around and/or are running on extremly slow hardware - OR - your profiling looks completly different and something makes that calls extremly expensive. Perhaps a certain setup, some added controllers or custom scripts or a bug that doesn't show up on my side while testing.

Don't get me wrong, I'd like to take that serious and investigate this. Many users have reported this, so there must be something going on. I just don't see it. Would you mind running the profiler and give me some details, perhaps you'd like to send me an example scene to jake<at>fluffyunderware<dot>com.

Ok so went back to my scene and changed all splines to Update and made sure Check Transforms is off, in my profiler I have 67 calls to CurvySpline.Update which ends up being .07 ms ... thats not too bad. I think the spikes I was noticing before are when GameObjects are enabled / disabled. In my game I've divided sections of the level that get streamed in and out depending on neighbor visibility. When one of these sectors with a bunch of curves is enabled, it racks up: 480 Bytes GC Alloc and .85 ms ... So probably was a mix of Check Transforms and enable / disable. I still think a No Update mode is a good idea, with it set to NoUpdate I get : 67 calls 0ms all the time, even when enabling or disabling any amount of sectors in my project.
Reply
#4
When you enable splines, the caches are (re-)built and all sorts of precalculation done. So either initialize them all at once at level start or reduce CacheSize if that's appropriate.
Reply
#5
(04-21-2016, 09:49 PM)invadererik Wrote: I have a lot of splines, I don't ever move them, they are static. Why do they need to Update ? 

Can there be a "No Update" mode ? I tried adding one, but then querying spline info does not 
seem to work anymore.

I've added : 
            if (m_UpdateIn == CurvyUpdateMethod.NoUpdate)
                doUpdate();


to the OnEnable call for CurvySpline.cs :  

that seems to make it work, although would be better if it didn't have to refresh the spline OnEnable, just use the data from Editor, I'm going to keep on modding it. Is there a better way to just generate the spline and never update ?


OK I think this does it: 

moved the code all the way to the top of the OnEnable() function:

            if (m_UpdateIn == CurvyUpdateMethod.NoUpdate)
            {
                mIsInitialized = true;
                doUpdate();
                return;
            }


This effectively makes the splines almost zero cost all the time. Not sure what effect it might have in the Editor, but
you can switch it back to Update when editing the splines and switch it back to NoUpdate once you are done. 

Anyway I suggest this small change, should be added to next version !  Big Grin

Hey - many thanks for this.  Made the change so see if I get any side effects  Cool

It might be useful for me when instantiating objects with splines from a pooling solution Smile

cheers

Nalin
Reply
#6
(04-27-2016, 07:38 PM)invadererik Wrote: I still think a No Update mode is a good idea, with it set to NoUpdate I get : 67 calls 0ms all the time, even when enabling or disabling any amount of sectors in my project.
That's a very bad idea. If you don't let the spline initialize after enabling, you can't use it, so why enable it at all then? On the other side, a spline costs almost nothing once enabled. Why not keeping all splines enabled and use other ways to track enabled/disabled state, e.g. a flag or a manager class?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a question about curvySpline haifeng.huang 12 32 07-14-2023, 09:34 AM
Last Post: _Aka_
  "Deadloop in CurvySPline.Refresh" spam Valkymaera 3 11 05-30-2023, 10:56 AM
Last Post: _Aka_
  Calling Update with defined deltatime Marco Schultz 3 8 01-25-2023, 01:58 PM
Last Post: _Aka_
  I want SetLocalPositions to update all CPs at once. yanke 3 7 05-30-2022, 02:50 PM
Last Post: _Aka_

Forum Jump: