Version: Unity 6.0 (6000.0)
语言 : 中文
脚本限制
条件编译

Burst compilation

Burst is a compiler that works on a subset of C# referred to in the Unity context as High-Performance C# (HPC#). Burst uses LLVM to translate .NET Intermediate Language (IL) to code that’s optimized for performance on the target CPU architecture.

Burst was originally designed for use with Unity’s job system. Jobs are structs that implement the IJob interface and represent small units of work that can run in parallel to make best use of all available CPU cores. Designing or refactoring your project to split work into Burst-compiled jobs can significantly improve the performance of CPU-bound code. For more information, refer to Write multithreaded code with the job system.

Aside from jobs, Burst can also compile static methods, as long as the code inside them belongs to the supported subset of C#. For more information on what’s included in High-Performance C#, refer to HPC# overview.

Burst is central to Unity’s Entity Component System (ECS) technologies, which includes a series of interdependent packages that work together to produce high performance code. However, Burst can be used independently of ECS and can be integrated into any Unity project that uses supported C# features.

For more information on Burst, refer to the Burst compiler package documentation.

Burst’s role in the compilation pipeline

Burst is not a complete scripting back end because it only supports a subset of C#. It can’t replace Mono or IL2CPP in your project but is supplemental to either of them.

When you include the Burst package in your project, the scripting back end compiles the code by default and Burst compiles whichever Burst-compatible parts of it are marked for Burst compilation.

Your C# scripts compile to Intermediate Language (IL) as usual. For methods marked for Burst, that IL is further compiled by Burst into native code. Burst compiles just-in-time (JIT) in the Unity Editor’s Play mode but ahead-of-time (AOT) in Player builds.

The subset of C# supported by Burst doesn’t support managed objects. Unity has packages designed to provide Burst-compatible versions of common types and data structures. The Collections package offers Burst-compatible collections such as arrays and lists, and Unity Mathematics offers Burst-compatible mathematics functions.

Compiling with Burst

Code is Burst compiled if the following conditions are met:

You can use the scripting symbol ENABLE_BURST_AOT to conditionally compile sections of your code only when the Burst AOT compilation setting is enabled.

For more information, refer to Burst compilation

Additional resources

脚本限制
条件编译
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961