Search Unity

How to disable ENABLE_UNITY_COLLECTIONS_CHECKS ?

Discussion in 'Entity Component System' started by 5argon, Dec 17, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I have tried checking/unchecking everything in the Jobs title bar and this
    ENABLE_UNITY_COLLECTIONS_CHECKS
    flag still appears in all my .sln/.csproj file. (Where is the mechanism that makes Unity add this flag?) My understanding is that
    ENABLE_UNITY_COLLECTIONS_CHECKS
    do not appears in the real build no matter what.

    The problem at development time is that Burst Inspector generates a code that goes in #if
    ENABLE_UNITY_COLLECTIONS_CHECKS
    and
    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    , making it hard to see the actual assembly. Every time I access NativeArray I would get a wall of safety check assembly. Everything here until the last movabs is the safety check code for using NativeArray get accessor :

    Screenshot 2018-12-17 04.47.27.png
     
  2. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    As far as know, it is hardcoded in Editor, there's no way to disable it nor enable it in the Player.
     
  3. futurlab_peterh

    futurlab_peterh

    Joined:
    Jan 23, 2018
    Posts:
    38
    Not being able to disable this makes some things almost impossible to test on Editor.

    On a prototype I'm working on, we make changes to a texture using its NativeArray - making a few thousand accesses is virtually instant on builds but amounts to over 80ms on Editor.

    In another project that makes heavy use of DOTS, development builds became pretty much useless because of the performance hit caused by checks like this, making them run at 5-10fps when their release versions run above 40fps. We've tried disabling Jobs Safety Checks but that didn't seem to help much.

    @Joachim_Ante is offering a way to toggle this down somewhere in the roadmap?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    >On a prototype I'm working on, we make changes to a texture using its NativeArray - making a few thousand accesses >is virtually instant on builds but amounts to over 80ms on Editor.

    Is the code using burst?

    Burst is able to switch checks on & off on demand via the Burst menu. Normal C# code does not, it is dependent on if in editor vs player.
     
    futurlab_peterh likes this.
  5. futurlab_peterh

    futurlab_peterh

    Joined:
    Jan 23, 2018
    Posts:
    38

    The code that access the texture's NativeArray isn't using Burst (there are no systems or jobs, actually). Using Burst on general static methods isn't available yet, is it? I'll try moving the logic to a Burst-compiled job and see what happens.
     
  6. Deleted User

    Deleted User

    Guest

    You may use FunctionPointer<T>
     
    Opeth001 and futurlab_peterh like this.
  7. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    The reason for this is not only safety checks. In the editor/development build, your code is compiled and executed via JIT/AoT (with Burst/IL2CPP) in debug mode while in the normal standalone everything is done using release optimizations, which is from where the most significant performance gains are coming from.
     
    Last edited: Jul 31, 2019
    misoin and futurlab_peterh like this.
  8. futurlab_peterh

    futurlab_peterh

    Joined:
    Jan 23, 2018
    Posts:
    38
    Yeah that makes perfect sense. In my post I mixed 2 different problems, though: there's a huge performance gap not only between Editor and builds, but also between Development and Release builds.

    In the texture's NativeArray case, running Development builds is perfectly fine - I'll test the suggestions to burst compile and/or jobify the texture manipulation, I believe they'll help when testing on Editor.


    In the DOTS project, we're facing massive performance differences when running Development/Release builds, much worse than anything I've seen in dozens of other Unity projects. This is consistent across 4 platforms (PC, PS4, XBOX and Switch), although it hits PS4 and Switch a lot harder. But I think this 2nd issue should be discussed in another thread in more details - I'll update this thread with a link to it once I do that.
     
    nxrighthere likes this.
  9. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    I accidentally submitted a post before I was done typing. In the development build the code is compiled in debug mode like in the editor, compiler generating debug symbols and doesn't perform optimizations that done in the release build (you can verify this with assembly editor or by just comparing the size of your assemblies between the two builds).
     
    Last edited: Aug 1, 2019
  10. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,116
    Not able to Burst a Function.

    Code (CSharp):
    1.  
    2. public static class C
    3. {
    4.     public const float Epsilon = 0.0001f;
    5.     [BurstCompile]
    6.     public static bool _isEqualToForBurst(float2 A, float2 B)
    7.     {
    8.         if ((A.x - B.x < Epsilon) && (A.y - B.y < Epsilon))
    9.             return true;
    10.         else
    11.             return false;
    12.     }
    13.  
    14. }
    15.  
    16.  
    17.  
    18. var  burstedFloat2IsEqual = BurstCompiler.CompileFunctionPointer<Func<float2,float2,bool>>( C._isEqualToForBurst);
    19.  

    Error 1:
    Unexpected exception Burst.Compiler.IL.Helpers.MethodDecoderException: Unable to decode `C, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null::_isEqualToForBurst(Unity.Mathematics.float2, Unity.Mathematics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null|Unity.Mathematics.float2, Unity.Mathematics, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)` ---> Burst.Compiler.IL.Helpers.MethodDecoderException: Unable to decode method after `C, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null::`
    at Burst.Compiler.IL.Helpers.CecilInterop+MethodParser.DecodeMethodName () [0x00037] in <2c9ff9fb581642acaeb86844246ad423>:0
    at Burst.Compiler.IL.Helpers.CecilInterop+MethodParser.DecodeMethod () [0x00027] in <2c9ff9fb581642acaeb86844246ad423>:0
    at Burst.Compiler.IL.Helpers.CecilInterop.DecodeMethodFromString (System.String fullMethodName) [0x00017] in <2c9ff9fb581642acaeb86844246ad423>:0

    --- End of inner exception stack trace ---
    at Burst.Compiler.IL.Helpers.CecilInterop.DecodeMethodFromString (System.String fullMethodName) [0x00033] in <2c9ff9fb581642acaeb86844246ad423>:0
    at Burst.Compiler.IL.Jit.JitCompilerService.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job) [0x001ba] in <2c9ff9fb581642acaeb86844246ad423>:0




    Error 2:
    InvalidOperationException: Burst failed to compile the given delegate: Boolean _isEqualToForBurst(Unity.Mathematics.float2, Unity.Mathematics.float2)
    attribute: Unity.Burst.BurstCompileAttribute

    Unity.Burst.BurstCompiler.Compile[T] (T delegateObj) (at Library/PackageCache/com.unity.burst@1.1.1/Runtime/BurstCompiler.cs:120)
    Unity.Burst.BurstCompiler.CompileFunctionPointer[T] (T delegateMethod) (at Library/PackageCache/com.unity.burst@1.1.1/Runtime/BurstCompiler.cs:78)
    CWBR.Client.Systems.PlayersAnimationsSystem.OnCreate () (at Assets/Scripts/ECS/Systems/ClientSideOnly/PlayersAnimationsSystem.cs:49)
    Unity.Entities.ComponentSystemBase.CreateInstance (Unity.Entities.World world) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/ComponentSystem.cs:189)
    Unity.Entities.World.AddSystem[T] (T system) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/World.cs:341)
    Unity.Entities.World.CreateSystemInternal (System.Type type, System.Object[] constructorArguments) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/World.cs:235)
    Unity.Entities.World.GetOrCreateSystemInternal (System.Type type) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/World.cs:251)
    Unity.Entities.World.GetOrCreateSystem (System.Type type) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/World.cs:279)
    Unity.Entities.DefaultWorldInitialization.GetOrCreateManagerAndLogException (Unity.Entities.World world, System.Type type) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:42)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities/Stubs/Unity/Debug.cs:25)
    Unity.Entities.DefaultWorldInitialization:GetOrCreateManagerAndLogException(World, Type) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:46)
    Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities.Hybrid/Injection/DefaultWorldInitialization.cs:119)
    Unity.Entities.AutomaticWorldBootstrap:Initialize() (at Library/PackageCache/com.unity.entities@0.1.0-preview/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:15)
     
  11. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @Opeth001
    1. Remove the underscore from method name it breaks parsing as well as violates C# naming conventions for methods.
    2. float2 can't be passed by value to an external functions with Burst at the moment (probably will be resolved in a future version of Burst).
     
    Opeth001 and Deleted User like this.