Search Unity

Large speed difference between editor and standalone player when using BURST

Discussion in 'Entity Component System' started by benzy54n, Apr 11, 2021.

  1. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    I have been racking my brain with this. I am generating a large map. Everything is setup with Jobs and Burst and on the Editor I can build my map in about 20 seconds. When I build the standalone player and run that building the same size map it takes around 120 seconds. It does appear that the burst generated .dll is being produced.

    Using Unity 2020.3.2f1.

    My Player settings seem correct.
    upload_2021-4-11_12-45-19.png
    Any help would be appreciated.
     

    Attached Files:

  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Are you building with the building configurations from the samples ?
     
  3. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    Hey Thanks for responding. Could you elaborate a little regarding the "building configurations from the samples"? Not quite understanding what that is.

    Thanks!
     
  4. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
  5. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
  6. sheredom

    sheredom

    Unity Technologies

    Joined:
    Jul 15, 2019
    Posts:
    300
    I've not seen this before myself - but if you can provide us a repro we'd definitely take a look at it!
     
    Nyanpas likes this.
  7. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I've done a few tests recently exporting Burst-jobs to various platforms to see how they perform. When building a mesh with a million vertices I seem to get better performance outside of Unity. There could be a lot of variables involved here if it is a complex setup. I just use the default settings (Windows Standalone).
     
  8. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    I have timings throughout my execution so I was able to analyze that:

    Editor Timings:
    upload_2021-4-15_13-13-49.png
    Summary:
    Some of my time stamps are as good or better from the editor to the .exe. Some of them are WAY slower. I double checked with the jobs in those timing segments. It seems like the jobs where I tried to use generics with were the culprits.

    For example:
    Code (CSharp):
    1. [BurstCompile(CompileSynchronously = true)]
    2. public struct GenerateHeightMap<T> : IJobParallelFor where T : struct, WorldGenNoiseStructInterface
    3. {
    4.     [ReadOnly]
    5.     public NativeArray<TilePositionDataStruct> TilePosData;
    6.     [ReadOnly]
    7.     public NativeArray<float2> VerticeLoadout;
    8.  
    9.     public int VertSize;
    10.  
    11.     [ReadOnly]
    12.     public T NoiseFunction;
    13.     [ReadOnly]
    14.     public NativeHashMap<NoiseOctaveIndex, NoiseConfigData> NoiseConfigs;
    15.  
    16.     //Output
    17.     public NativeArray<float> Heights;
    So this is the issue. These job structures are performing as expected in the editor but not in the exe. Any thoughts would be appreciated.
     
  9. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    Furthermore the function GenerateHeightMap is not showing up in the Burst Inspector within the editor nor is it showing up in the lib_burst_generated.txt file of the .exe compilation
     
  10. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    First idea would be that burst JIT compiles the generic job type when it is used in the editor, but it can't statically determine which generic version to precompile for a build (if it could, it'd show up in the inspector) - so it runs managed instead?

    Do you explicitly use GenerateHeightMap<something> where something is an actual type, or is it 'nested' generics?
     
    benzy54n likes this.
  11. sheredom

    sheredom

    Unity Technologies

    Joined:
    Jul 15, 2019
    Posts:
    300
    benzy54n likes this.
  12. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    Thanks guys. This does appear to be my issue. I should have read this in the manual. Looks like I have some re-architecting to do.
     
    sheredom likes this.