Search Unity

WaitForJobGroupID takes 0.1~0.2ms on the Main Thread

Discussion in 'Entity Component System' started by alexandre-fiset, May 14, 2019.

  1. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    So I have a ComponentSystem (non-Job) that needs the data from another system, this time a JobComponentSystem.

    It looks like this stalls the main thread until my system receives the data from the job. Is there a way to avoid this? To ensure my ForEach gets called only when that job is done? And not stall the main thread in the meantime?

    This currently accounts to 0.1~0.2ms spent only on WaitForJobGroupID. In a hybrid approach I did not expect things to just wait like this, especially on the main thread and with the UpdateAfter(MyJobSystem) tag applied. My use case is quite simple, but I fear that adding more systems will only make things worse.

    This is how it looks like in the profiler (in a build), tested in both DeepProfile and standard.

    upload_2019-5-14_16-1-34.png
     
    Tony_Max likes this.
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    To get the best performance you need all your systems to be JobComponentSystem. This way no systems cause syncpoints.
     
  3. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    Unity has way too many things that can't be jobbed such as Light, Volumes, Animator and so on, so I guess the best now it to not use jobs for anything directly or indirectly bound to these?

    For a day-night cycle system, I was processing time, time spans, rotations and other stuff in jobs, but I just found it's much faster when done outside of jobs as this avoid the stalls.