How to disable ENABLE_UNITY_COLLECTIONS_CHECKS ?

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 :

As far as know, it is hardcoded in Editor, there’s no way to disable it nor enable it in the Player.

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_1 is offering a way to toggle this down somewhere in the roadmap?

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.

1 Like

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.

You may use FunctionPointer

2 Likes

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.

2 Likes

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.

1 Like

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).

Not able to Burst a Function.

public static class C
{
    public const float Epsilon = 0.0001f;
    [BurstCompile]
    public static bool _isEqualToForBurst(float2 A, float2 B)
    {
        if ((A.x - B.x < Epsilon) && (A.y - B.y < Epsilon))
            return true;
        else
            return false;
    }

}



var  burstedFloat2IsEqual = BurstCompiler.CompileFunctionPointer<Func<float2,float2,bool>>( C._isEqualToForBurst);

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)

@Opeth001

  • Remove the underscore from method name it breaks parsing as well as violates C# naming conventions for methods.
  • 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).
2 Likes