Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How many Jobs does IJobEntity.ScheduleParallel() create?

Discussion in 'Entity Component System' started by Explaysive, Apr 28, 2023.

  1. Explaysive

    Explaysive

    Joined:
    Nov 10, 2018
    Posts:
    1
    Hey!

    I have been wondering how many Jobs IJobEntity creates.

    I have read in Unity’s DOTS Best Practices that you should change the number of Jobs being started if they generate too much Overhead. And in another Forum Post, it was stated that Jobs should generally take >0.05ms to keep the Overhead at a reasonable level.


    So, if I have, e.g., 100_000 Components with the UnitTag Component, how many Jobs would new JobTest().ScheduleParallel() create? (see Code example below)


    In the Docs it says that IJobEntity uses IJobEntityBatch, so I would assume the number of created Jobs comes down to the number of Chunks.

    So, let’s say 1 Chunk = 1000 Components ---> 100_000 / 1000 = 100. In that example JobTest().ScheduleParallel() would create 100 Jobs?


    But what if 1 Job takes 0.01 ms and thus generates more Overhead than Work. How would I be able to manually tell the API to only create e.g.: 10 Jobs, in order to minimize the Overhead? Does it even create those 100 Jobs or have I interpreted it wrong?

    Code (CSharp):
    1.  
    2. public partial struct MySystem : ISystem
    3. {
    4.    public void OnCreate(ref SystemState state)  { }
    5.    public void OnDestroy(ref SystemState state) { }
    6.    public void OnUpdate(ref SystemState state)
    7.    {
    8.          new MyJob().ScheduleParallel();
    9.    }
    10. }
    11.  
    12. public partial struct MyJob : IJobEntity
    13. {
    14.       public void Execute(RefRO<UnitTag> unitTag)
    15.       {
    16.             // DO SOMETHING
    17.       }
    18. }
    19.  
    20. public struct UnitTag : IComponentData {}
    21.