Search Unity

Slow Automatic World Bootstrap when using [UpdateInGroup],[UpdateAfter] and [UpdateBefore]

Discussion in 'Entity Component System' started by vaveva, Nov 21, 2018.

  1. vaveva

    vaveva

    Joined:
    Aug 26, 2013
    Posts:
    5
    Hello,

    We are using multiple systems (around 100) using [UpdateInGroup],[UpdateAfter] and [UpdateBefore] and we found that the automatic world bootstrap is very slow (more than 5 minutes).
    After multiple tests we found that this part of the ScriptBehaviourUpdateOrder is very slow :

    Code (CSharp):
    1. // Validate that the chains are not over constrained with combinations of system and engine dependencies
    2.             foreach (var typeAndSystem in dependencyGraph)
    3.             {
    4.                 var system = typeAndSystem.Value;
    5.                 if (system.UpdateBefore.Count == 0)
    6.                     ValidateAndFixSingleChainMaxPos(system, dependencyGraph, system.MaxInsertPos);
    7.                 if (system.UpdateAfter.Count == 0)
    8.                     ValidateAndFixSingleChainMinPos(system, dependencyGraph, system.MinInsertPos);
    9.             }
    We also think that Injected Barrier Systems may worsen the problem.

    Are there any guidelines about that ?
     
    floboc likes this.
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    This was discussed a while.

    Basically at the moment, adding UpdateAfter and UpdateBefore gets exponentially more expensive.

    I think from memory only using 1 type (only UpdateAfter or only UpdateBefore) is significantly better, but in general I think you should avoid using them except for very specific cases.

    1 frame delay on certain updates is really not an issue a lot of the time and having dozens or even hundreds of update attributes becomes unmanageable.

    -edit-

    here we go, dug up some posts.

    Discussion on this and why the performance is so bad (and the linear solution).

    https://forum.unity.com/threads/tak...ymode-be-mindful-of-your-updateorders.543283/

    Also it's going to be changed

    https://forum.unity.com/threads/update-interval.523628/#post-3610044

    -edit2-

    My personal hope we have a simple integer order.

    [UpdateOrder(1)]
    [UpdateOrder(-3)]
    [UpdateOrder(4)]

    Solves order and grouping without any magic behind it.

    Basically how unity works atm.
     
    Last edited: Nov 22, 2018
  3. vaveva

    vaveva

    Joined:
    Aug 26, 2013
    Posts:
    5
    Thanks, we will try to find a way to make it works.
     
    Last edited: Nov 22, 2018