Burst compilation in Play mode
Burst provides the option to compile asynchronously or synchronously in Play mode. Understand these options and how and when to configure synchronous compilation.
阅读时间1 分钟最后更新于 13 小时前
When you create a build of your project, Burst compiles all the supported code ahead-of-time (AOT) into a native library which Unity ships with your application.
When previewing your application in the Editor's Play mode, Burst provides the following compilation modes:
- Asynchronous: Parts of your code marked for Burst compilation can run as managed, just-in-time (JIT) compiled code in the .NET runtime while waiting for Burst compilation to complete. This is the default behavior.
- Synchronous: Parts of your code marked for Burst compilation can only run as Burst-compiled native code and your application must wait for Burst compilation to complete.
Synchronous compilation
To force synchronous compilation in Play mode, set the property to as follows:
CompileSynchronouslytrue[BurstCompile(CompileSynchronously = true)]public struct MyJob : IJob{ // ...}
Waiting for synchronous compilation affects the current running frame, which can cause hitches and make your application unresponsive. Synchronous compilation is only recommended in the following situations:
- If you have a long running job that only runs once. The performance of the compiled code might outweigh the downsides of synchronous compilation.
- If you're profiling a Burst job and want to test the code from the Burst compiler. When you do this, perform a warmup to discard any timing measurements from the first call to the job. This is because the profiling data includes the compilation time and skews the result.
- To aid with debugging the difference between managed and Burst compiled code.