Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

IJobParallelForTransform, 15000 transforms, executed on single job thread, any hints?

Discussion in 'Entity Component System and C# Job system' started by jakub-gemrot, Jun 25, 2018.

  1. jakub-gemrot

    jakub-gemrot

    Joined:
    Nov 1, 2014
    Posts:
    5
    Hi!

    I'm playing with Job System, implemented simple scenario where cubes are falling down and being respawned once they hit a certain Y level. I have two jobs, the second dependent on the first. They both are referencing the same native array for transforms. It runs without errors/warnings but the job is never split among job threads.

    Job's code:
    Code (CSharp):
    1. namespace Ships.JobSystem
    2. {
    3.     [BurstCompile]
    4.     public struct MoveJob : IJobParallelForTransform
    5.     {      
    6.         public float speed;
    7.         public float deltaTime;
    8.  
    9.         public void Execute(int index, TransformAccess transform)
    10.         {
    11.             Vector3 position = transform.position;
    12.  
    13.             position = position + new Vector3(0, speed, 0) * deltaTime;
    14.  
    15.             transform.position = position;
    16.         }
    17.     }
    18. }

    Profiler as the proof (development build, not taken from the editor):
    Unity-JobSystem-Question.png


    Stats window:
    Unity-JobSystem-Question.2.png

    I'm running

    Version 2018.2.0b8 (fed204371f5a)
    Wed, 30 May 2018 15:35:38 GMT
    Branch: 2018.2/staging

    My project manifest:

    Code (CSharp):
    1. {
    2.     "dependencies": {
    3.         "com.unity.modules.ui": "1.0.0",
    4.         "com.unity.modules.tilemap": "1.0.0",
    5.         "com.unity.modules.physics2d": "1.0.0",
    6.         "com.unity.modules.assetbundle": "1.0.0",
    7.         "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    8.         "com.unity.modules.unityanalytics": "1.0.0",
    9.         "com.unity.modules.umbra": "1.0.0",
    10.         "com.unity.analytics": "2.0.16",
    11.         "com.unity.modules.vehicles": "1.0.0",
    12.         "com.unity.ads": "2.0.8",
    13.         "com.unity.modules.imageconversion": "1.0.0",
    14.         "com.unity.modules.director": "1.0.0",
    15.         "com.unity.modules.video": "1.0.0",
    16.         "com.unity.modules.audio": "1.0.0",
    17.         "com.unity.modules.unitywebrequest": "1.0.0",
    18.         "com.unity.textmeshpro": "1.2.1",
    19.         "com.unity.modules.ai": "1.0.0",
    20.         "com.unity.modules.unitywebrequestwww": "1.0.0",
    21.         "com.unity.purchasing": "2.0.1",
    22.         "com.unity.modules.particlesystem": "1.0.0",
    23.         "com.unity.standardevents": "1.0.13",
    24.         "com.unity.modules.imgui": "1.0.0",
    25.         "com.unity.modules.physics": "1.0.0",
    26.         "com.unity.modules.screencapture": "1.0.0",
    27.         "com.unity.modules.xr": "1.0.0",
    28.         "com.unity.modules.terrain": "1.0.0",
    29.         "com.unity.modules.unitywebrequestaudio": "1.0.0",
    30.         "com.unity.modules.jsonserialize": "1.0.0",
    31.         "com.unity.modules.terrainphysics": "1.0.0",
    32.         "com.unity.entities": "0.0.12-preview.6",
    33.         "com.unity.modules.animation": "1.0.0",
    34.         "com.unity.package-manager-ui": "2.0.0-preview.3",
    35.         "com.unity.modules.cloth": "1.0.0",
    36.         "com.unity.modules.uielements": "1.0.0",
    37.         "com.unity.modules.vr": "1.0.0",
    38.         "com.unity.modules.unitywebrequesttexture": "1.0.0",
    39.         "com.unity.modules.wind": "1.0.0",
    40.         "com.unity.incrementalcompiler": "0.0.42-preview.1"
    41.     },
    42.     "registry": "https://packages.unity.com",
    43.     "testables": [
    44.         "com.unity.collections",
    45.         "com.unity.entities",
    46.         "com.unity.jobs"
    47.     ]
    48. }
    Any suggestions what I might have missed to make my job be split among threads?

    Thank you!
    Jakub
     
  2. jakub-gemrot

    jakub-gemrot

    Joined:
    Nov 1, 2014
    Posts:
    5
    Can it be that IJobParallelForTransform does not have an extension for setting the grouping?

    I have to schedule it like this:
    Code (CSharp):
    1. shipTransforms.moveJobHandle = moveJob.Schedule(shipTransforms.shipsAccess);
    While the code within ShipMoveJob is small, it still takes 2ms at single thread so by using 7 threads it can get down to 0,28ms...

    Jakub
     
  3. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    394
    IJobParallelForTransform only splits the roots. if all your transforms have the same parent, they will execute in the same thread.

    try removing the parents for your cubes if you have any (or grouping them under different roots, at least >= the number of CPU threads)
     
  4. jakub-gemrot

    jakub-gemrot

    Joined:
    Nov 1, 2014
    Posts:
    5
    M_R is correct, I've split my objects among different parents and it works like a charm.
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    24,963
    Unity needs a concept of a static parent or decorative parent so we can still keep things organised.