Version: Unity 6.6 Beta (6000.6)
Language : English
Configure Burst compilation
Excluding code from Burst compilation

Marking code for Burst compilation

Apply the [BurstCompile] attribute to the parts of your code you want Burst to compile. You can apply the [BurstCompile] attribute to the following:

  • Jobs: When you apply [BurstCompile] to a job definition, Burst compiles everything within the job. For more information on jobs, refer to Job system.
  • Classes: Apply [BurstCompile] to a class definition if the class contains static methods that are also marked with [BurstCompile]. Burst can’t compile the class itself but only its member methods.
  • Structs: Apply [BurstCompile] to a regular (non-job) struct definition if the struct contains static methods that are also marked with [BurstCompile].
  • Static methods: Apply [BurstCompile] to the method and its parent type. To work with dynamic functions that process data based on other data states, refer to Function pointers.
  • Assemblies: Apply [BurstCompile] to an assembly to set options for all Burst jobs and function-pointers within the assembly. For more information, refer to Defining Burst options for an assembly.

Note: You don’t always need to mark a method with the [BurstCompile] attribute for Burst to compile it. Any method where the program execution switches from managed to Burst-compiled code is referred to as a Burst entry point. If a static entry point method is marked with [BurstCompile], Burst also compiles any methods it calls into, even if they’re not marked [BurstCompile].

Configure Burst compilation with parameters

You can supply parameters to the [BurstCompile] attribute to modify aspects of compilation and improve Burst’s performance. You can use attribute parameters to:

  • Use a different accuracy for math functions (for example, sin, cos).
  • Relax the order of math computations so that Burst can rearrange the floating point calculations.
  • Force a synchronous compilation of a job (only for just-in-time compilation).

For example, you can use the [BurstCompile] attribute to change the floating precision and float mode of Burst as follows:

[BurstCompile(FloatPrecision.Medium, FloatMode.Fast)]

For more information on configuring precision and determinism in floating point calculations, refer to Float precision and determinism.

Additional resources

Configure Burst compilation
Excluding code from Burst compilation