Search Unity

Performance hit for hinting NativeArray usage in Burst compiled Job?

Discussion in 'Burst' started by funkyCoty, Jan 5, 2020.

  1. funkyCoty

    funkyCoty

    Joined:
    May 22, 2018
    Posts:
    727
    My profiler is showing that a particular job set takes nearly 4ms in the Editor while normal profiling (using the Profiler class to sample) when my code looks like this:

    Code (CSharp):
    1.        
    2.         [ReadOnly] public NativeArray<float> densities_batched;
    3.         [ReadOnly] public NativeArray<int> blockIds_batched;
    4.  
    5.         [NativeDisableParallelForRestriction] public NativeArray<float> densities000;
    6.         [NativeDisableParallelForRestriction] public NativeArray<int> blockIds000;
    7.  
    However, if my code looks like the following, that 4ms drops to nearly 0ms.
    Code (CSharp):
    1.      
    2.         [NativeDisableContainerSafetyRestriction] public NativeArray<float> densities_batched;
    3.         [NativeDisableContainerSafetyRestriction] public NativeArray<int> blockIds_batched;
    4.  
    5.         [NativeDisableContainerSafetyRestriction] public NativeArray<float> densities000;
    6.         [NativeDisableContainerSafetyRestriction] public NativeArray<int> blockIds000;
    7.  
    Keep in mind, I'm scheduling ~100 IJobParallelFor jobs, each one depending on the last. Is the reason for the performance hit of scheduling due to the safety checks? Or is this a Unity bug? Should I expect these performance hits to be editor-only? Thanks.

    edit: seems like its editor only, but its still a pretty huge hit in the editor and makes testing pretty frustrating.
     
    Last edited: Jan 5, 2020
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    This is most likely the job debugger taking time. It can be turned off in the JobsDebugger.
    Especially long chains of dependencies can be expensive to analyze.
     
    funkyCoty likes this.