Unity Job System基本介绍

        为什么使用Job System?

        1. Job System可以被Burst编译器优化,Burst编译器专为Jobs优化而设计,提供了类似shader的强大编译优化能力,支持Loop Vectorization和很多编译优化选项,详情参考这里:

Optimization Guidelines | Burst | 1.4.11https://docs.unity3d.com/Packages/[email protected]/manual/docs/OptimizationGuidelines.html        2. Job System可以并发执行任务,充分利用CPU的多核并发能力

        3. Job System是基于blittable-types,也就是unmanaged code,省掉了内存管理的开销,对这一点不熟悉可以参考:

Unity - Manual: Managed memoryhttps://docs.unity3d.com/Manual/performance-managed-memory.htmlBlittable and Non-Blittable Types - .NET Framework | Microsoft LearnLearn about blittable and non-blittable types. Blittable data types are commonly represented in managed and unmanaged memory and don't need special handling.https://learn.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types

Managed and Unmanaged Code - Key Differences - ParTechThis blog is a continuation of our previous blog on Unsafe code and captures the key differences between unmanaged code and managed code along with their respective advantages and disadvantages.https://www.partech.nl/en/publications/2021/03/managed-and-unmanaged-code---key-differences#        缺点:

        1. 需要自己手动控制资源回收,这个过程需要更加小心,因为C#不再会做安全性检查,需要由开发者自己保证资源回收正确。

        2. 跟线性流程不同,我们必须手动控制多线程依赖关系,保证资源同步并且不会发生竞争。

        3. 依赖于blittable-types,不能使用引用类型。并且常用的一些数据需要改写成vector types以利用Burst对SIMD指令的优化,需要尽量使用Unity.Mathematics类型代替旧的类型,这种替换和改写需要工作量。

总结:

        适合处理成为CPU瓶颈,并且依赖性不强,可以通过并发优化的工作。

附一些Job System入门教程:

Unity - Manual: Job system overview

Quick Start | Burst | 1.4.11

Unity - Scripting API: IJobFor

猜你喜欢

转载自blog.csdn.net/paserity/article/details/130024124
job
今日推荐