Search Unity

(Case 1035318) RaycastCommands issue on Linux

Discussion in 'Entity Component System' started by ReliCWeb, May 4, 2018.

  1. ReliCWeb

    ReliCWeb

    Joined:
    Apr 18, 2013
    Posts:
    17
    Hey all, I've been waiting for the 2018.1.0f2 Linux editor to release and it finally has. However I seem to be running into odd performance issues specifically with RaycastCommands in jobs. Here's my scenario:

    Packages:
    - Jobs 0.0.7-preview.1
    - Entities 0.0.12-preview.1
    - Collections 0.0.9-preview.1
    - Mathematics 0.0.12-preview.2
    - Burst: 0.2.4-preview.4

    Test: 128k Raycasts (point cloud generation) @ 10Hz

    System 1: Windows 10 Laptop
    CPU: i7-6700HQ 2.6GHz
    GPU: GTX 1060 6GB
    RAM: 16GB
    In-Editor benchmark: 20-30 fps

    System 2: Ubuntu 16.04 Desktop
    CPU: i7-7700K 4.2GHz
    GPU: GTX 1060 6GB
    RAM: 32GB
    In-Editor benchmark: <=1 fps

    Looking at the profiler timeline (to examine threads) I see that BatchQuery.ExecuteRaycastJob takes about 67ms on System 1, but takes 269ms on System 2.

    I then ran another benchmark test using a "Pure" ECS setup to manipulate 10k cubes, which is completely dependent on the Job System. This benchmark ran fine on both systems, so it seems the issue may be localized to RaycastCommands/BatchQuery.ExecuteRaycastJob. System 2 reliably outperforms System 1 in all other areas.

    NOTE: I have not tested this with previous beta versions of 2018 or other package versions.

    My questions are as follows: Are there any known issues with the Job System on Linux? Do I need to change a specific config setting to get this to work properly?

    Thanks!
     
  2. ReliCWeb

    ReliCWeb

    Joined:
    Apr 18, 2013
    Posts:
    17
    I've managed to mock up a basic example. If you use the same packages in my original post, put the script below in an empty scene on an empty GameObject, and you should see definite performance differences on Linux vs Windows.

    System 1 (Windows, same as original post):
    FPS: 28-32
    BatchQuery.ExecuteRaycastJob: 26ms

    System 2 (Linux, same as original post):
    FPS: 3-4
    BatchQuery.ExecuteRaycastJob: 203ms

    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Jobs;
    3. using Unity.Collections;
    4. using Unity.Mathematics;
    5.  
    6. public class RaycastTest : MonoBehaviour
    7. {
    8.     public int raycastCount = 100000;
    9.     public LayerMask raycastLayer;
    10.     public int batchCount = 256;
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         NativeArray<RaycastCommand> raycasts = new NativeArray<RaycastCommand>(raycastCount, Allocator.Temp);
    16.         NativeArray<RaycastHit> hits = new NativeArray<RaycastHit>(raycastCount, Allocator.Temp);
    17.  
    18.         JobPrepareRaycasts prepJob = new JobPrepareRaycasts()
    19.         {
    20.             commands = raycasts,
    21.             pos = new float3(0f, 0f, 0f),
    22.             dir = new float3(0f, 0f, 1f),
    23.             layer = raycastLayer
    24.         };
    25.         JobHandle prepHandle = prepJob.Schedule(raycastCount, batchCount);
    26.         JobHandle raycastHandle = RaycastCommand.ScheduleBatch(raycasts, hits, batchCount, prepHandle);
    27.  
    28.         JobHandle.ScheduleBatchedJobs();
    29.         raycastHandle.Complete();
    30.  
    31.         raycasts.Dispose();
    32.         hits.Dispose();
    33.     }
    34.  
    35.     [ComputeJobOptimization]
    36.     struct JobPrepareRaycasts : IJobParallelFor
    37.     {
    38.         public NativeArray<RaycastCommand> commands;
    39.         public float3 pos;
    40.         public float3 dir;
    41.         public LayerMask layer;
    42.  
    43.         public void Execute(int index)
    44.         {
    45.             commands[index] = new RaycastCommand(pos, dir, 250f, layer, 1);
    46.         }
    47.     }
    48. }
    49.  
     
  3. ReliCWeb

    ReliCWeb

    Joined:
    Apr 18, 2013
    Posts:
    17
    Ok I have now tested the above with non-preview versions of the packages and still get the same results.

    - Jobs 0.0.6
    - Entities 0.0.11
    - Collections 0.0.8
    - Mathematics 0.0.11
    - Burst: 0.2.3
     
  4. ReliCWeb

    ReliCWeb

    Joined:
    Apr 18, 2013
    Posts:
    17
    I've filed an official bug report with an easy-to-reproduce project. Case # 1035318.
     
  5. GabrieleUnity

    GabrieleUnity

    Unity Technologies

    Joined:
    Sep 4, 2012
    Posts:
    116
    Thanks for reporting the issue, it is definitely an unexpected behavior. We are looking at it.
     
    FROS7 likes this.
  6. ReliCWeb

    ReliCWeb

    Joined:
    Apr 18, 2013
    Posts:
    17
    Has there been any progress on this? I've been watching patch notes and testing new releases, but the issue still persists on Linux.

    Thanks.