Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Enter the 2020.2 Beta Sweepstakes for a chance to win an Oculus Quest 2.
    Dismiss Notice

[SOLVED] IJobProcessComponentData vs ComponentGroup performance difference?

Discussion in 'Data Oriented Technology Stack' started by Mr-Mechanical, Jan 6, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    501
    I've been optimizing a system and I've found that there seems to be a dramatic performance difference with filtering using IJobProcessComponentData and ComponentGroup/ComponentSystem. I am not sure why. I am using 2018.3.0f2 and testing on an early 2014 MacBook Air. This wouldn't normally be an issue as I could just use IJobProcessComponentData, but unfortunately, IJobProcessComponentData no longer fits all of my use cases. Thanks, any help would be appreciated.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,557
    IJobProcessComponentData might have a tiny bit more overhead than manual chunk iteration, but not significantly noticeable to warrant not using it.

    Some source code could help.
     
    Last edited: Jan 6, 2019
    Mr-Mechanical likes this.
  3. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    501
    I added a new system to my application and found that the performance hit was much higher than I expected. So I removed all the code but filtering bits. After removing everything but the barebones my ComponentSystem still caused performance issues. What's weird is when I switched to the less explicit IJobProcessComponentData it was for some reason way faster than ComponentSystem in my testing.

    Adding this empty system causes absolutely no performance trouble (80 fps)
    Code (CSharp):
    1. [UpdateAfter(typeof(PreviousSystem))]
    2. public class OKSystem : JobComponentSystem
    3. {
    4.         [BurstCompile]
    5.         struct Job : IJobProcessComponentData<SomeComponent>
    6.         {
    7.             public void Execute([ReadOnly] ref SomeComponent someComponent)
    8.             {
    9.  
    10.             }
    11.         }
    12.  
    13.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    14.         {
    15.             var job = new Job();
    16.             return job.Schedule(this, inputDeps);
    17.         }
    18.     }
    But for some reason using this ComponentSystem makes my fps go from 80 to 40 in standalone build
    Code (CSharp):
    1.  
    2. [UpdateAfter(typeof(PreviousSystem))]
    3.  public class TroubledSystem : ComponentSystem
    4.  {
    5.        ComponentGroup group;
    6.        protected override void OnCreateManager()
    7.        {
    8.               group = GetComponentGroup(ComponentType.ReadOnly(typeof(SomeComponent)));
    9.        }
    10.  
    11.       protected override void OnUpdate()
    12.       {
    13.  
    14.       }
    15.  }
    16.  
    I plan to test on different hardware and os soon. Maybe this issue is platform specific.
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,599
    IJobProcessComponentData is multi threaded.
    OnUpdate is single threaded.
    If that matter in your case?
     
    Mr-Mechanical likes this.
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,557
    You're comparing two things that can't really be compared here.
    You can use IJobProcessComponentData in ComponentSystem and ComponentGroup in JobComponentSystem.

    Why are you even switching to ComponentSystem?
     
    T-Zee, wobes and Mr-Mechanical like this.
  6. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    501
    Thank you guys :D :D. This has completely and utterly fixed my problem.
     
  7. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    501
    For some reason, I always thought ComponentSystem and ComponentGroup had something to do with each other. Thanks for clearing that up, I really appreciate it. Is it just that ComponentSystem is on main thread? What is ComponentSystem used for?
     
  8. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    651
    ComponentSystem is mainthread-only. It's mostly for hybrid code that needs to work on the main thread.

    It can act as a sync point like a BarrierSystem, as it even has it's own EntityCommandBuffer member:
    PostUpdateCommands
    .
     
    Mr-Mechanical likes this.
  9. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,557
    To put it as simple as possible

    JobComponentSystem is for work that uses jobs
    ComponentSystem is for work that doesn't use jobs

    This is obviously an oversimplify, you can still use jobs in component system you just have to finish them on the spot.

    It's usually used for hybrid code or syncing to stuff that needs the main thread (eg. applying a mesh etc.)

    -edit- beaten by a second.
     
    Last edited: Jan 6, 2019
    Derebeyi and Mr-Mechanical like this.
unityunity