---
title: 爆发编译
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/burst
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/scripting/compilation-and-code-reload/script-compilation/burst.md
generated_at: 2026-11-16T08:11:37.499Z
locale: zh-cn
---

# 爆发编译

> 使用 Unity 的 爆发 编译器器可以ON名为 高 性能 C# 的 C# 子集上编译代码，这些代码主要用于处理任务System。

爆发 编译器适用ON Unity 上下文中称为性能 C# (HPC#) 的 C# 子集。爆发使用 [LLVM](https://llvm.org/) 将 .NET [中级语言 (IL)](https://learn.microsoft.com/en-us/dotnet/standard/managed-code) 移动到针对 Target CPU 架构的性能进行优化的代码。

爆发 最初设计使用于 Unity 的任务System。作业是实现 [`IJob`](ScriptRef:UnityJobs.IJob) 接口的 structs，表示可以并行运行以使所有可用 CPU 核心得到最佳使用的小工作单位。设计或重构 Project 将工作拆分为爆发编译的作业可以显著提高 CPU 绑定代码的性能。有关更多信息，请参阅使用任务系统[编写多线程代码](/engine/6000.0/manual/scripting/optimization/job-system.md)。

除了作业之外，爆发 还可以编译Static方法，只要其中的代码属于受支持的 C# 子集即可。有关高性能 C# 中包含的内容的更多信息，请参阅 [HPC# Overview](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/csharp-hpc-overview.html)。

爆发是 Unity [实体组件系统 (ECS) 技术](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html?subfolder=/manual/ecs-packages.html)的核心，其中包括一系列相互依赖的包，全体学员可以协同工作来生成高性能代码。但是，爆发 可以独立于 ECS 使用，并且可以集成到Any使用受支持的 C# Features的 Unity Project中。

有关 ON 爆发的更多信息，请参阅[爆发编译器包文档](https://docs.unity3d.com/Packages/com.unity.burst@latest)。

## 编译管道中爆发的角色##burst's-role-in-the-compilation-pipeline

爆发不是完整的 [Scripting Backend](/engine/6000.0/manual/scripting-backend.md)，因为它仅支持 C# 的一个子集。它无法替换 Project 中的 [Mono](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/mono.md) 或 [IL2CPP](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp.md)，但可以补充两者之一。

当您在项目中包括爆发包时，Scripting Backend 默认情况下编译代码，爆发编译其中任何[标记为爆发编译](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/compilation-burstcompile.html)的与爆发兼容的部分。

C# 脚本往常一样编译为中级语言 (IL)。对于标记为爆发的方法，该 IL 会通过爆发进一步编译为原生代码。在 Unity Editor 的播放模式下爆发即时编译 (JIT)，但在 Player 构建中爆发提前 (AOT)。

爆发 支持的 C# 子集不SupportManaged对象。Unity 的包旨在提供常见类型和数据结构的爆发兼容版本。[Collections](https://docs.unity3d.com/Packages/com.unity.collections@latest) 包提供与爆发兼容的 Collections，例如数组和列表，[Unity Mathematics](https://docs.unity3d.com/Packages/com.unity.mathematics@latest) 提供与爆发兼容的 mathematics 函数。

## 使用爆发进行编译##compiling-with-burst

如果满足以下条件，则会爆发编译代码：

* 代码与[爆发兼容](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/csharp-hpc-overview.html)。
* 通过 Player 构建的 [爆发 AOT Settings](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/building-aot-settings.html) 或通过 Unity Editor 代码的[爆发菜单](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/editor-burst-menu.html)已启用爆发编译。
* 代码显式标记了 [`[BurstCompile]`](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/compilation-burstcompile.html) 属性或引用自 的代码。

仅当已启用爆发 AOT 编译设置时，才能使用[脚本符号](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/platform-dependent-compilation.md)`ENABLE_BURST_AOT`来有条件地编译代码部分。

有关更多信息，请参阅[爆发编译](https://docs.unity3d.com/Packages/com.unity.burst@latest/index.html?subfolder=/manual/compilation.html)

## 其他资源##additional-resources

* [爆发编译器包文档](https://docs.unity3d.com/Packages/com.unity.burst@latest)
* [任务系统](/engine/6000.0/manual/scripting/optimization/job-system.md)
