Unity Burst Compiler: Performance Optimization Made Easy

This year we saw the release of Red Dead Redemption
2 and Spider-Man, two AAA titles that pushed modern consoles to the absolute limit. Each game features a massive, simulated game
world that raises the bar for game development both artistically and technologically. Neither one would have been possible without
some extremely sophisticated code that was optimized to run efficiently on each individual
console. But these games were created by massive studios
with specialized teams that could focus specifically on performance. How can smaller studios and indie developers
keep up with the rate that the industry is changing? Well, in this video I’m going to show you
how the Unity Burst Compiler allows you to write extremely optimized game code without
a specialized team and with very little effort. But first. Are you interested in learning about Unity
ECS? Unity ECS is Unity’s new implementation of
the Entity Component System pattern. It leverages the new C# Job System to get
you the most performance by default. My series will walk you through how to create
your own survival shooter game using this exciting new feature set. You’ll learn how to use entities, components,
and systems to implement all of the functionality of the player. So what are you waiting for? Check out my series and get started with Unity
ECS today. So how do you squeeze the most performance
out of your code in Unity? Well, for one, you can leverage multithreading
using the C# Job System. Multithreaded code utilizes all of the cores
in your processor so it executes faster. Next, you can optimize the memory layout of
your code using Unity ECS. Data that’s organized properly in memory
is much easier for your CPU to access. And lastly, you can transform your dotnet
bytecode into highly optimized machine code that’s designed to run natively on the processor
of your target system. And that’s where the Unity Burst Compiler
comes in. At the end of the day, achieving the best
possible performance comes down utilizing the hardware to its fullest. And to do that, you need to optimize your
code at the lowest level. That means writing logic in languages like
C++, or even C, that can be executed directly on the processor. This opens up the door to some insane optimizations
like SIMD instructions, custom assemblers, and others that go beyond the scope of this
video. The drawback, however, –
Well, besides having to right painfully complex code –
Is that this approach blocks you from one of Unity’s most important features: the
ability to publish your game on multiple platforms. You see, Unity’s entire scripting platform
is based on an open-source project called Mono. Mono is an implementation of the .NET Framework
that can compile and run C Sharp code on a bunch of different software systems. On top of Windows, macOS, and most Linux distributions,
Mono can even run on PlayStation, Xbox, and Wii. It does this by compiling C Sharp scripts
into managed code, which is a type of program code that’s executed by something called
the Common Language Runtime virtual machine, or CLRVM. The CLRVM is what makes multiplatform building
possible. It manages the memory, garbage collection,
and execution of your code in a system agnostic way. And with it you can run C Sharp code on any
system that supports Mono. So it’s obviously pretty important because
it provides so much flexibility. But where you gain in flexibility you pay
in performance. Unfortunately, the cost of being able to execute
your code on multiple platforms is fairly high. And, while the great developers behind Mono
have put a lot of work into optimizing the platform, the performance of managed code
will never come close to that of unmanaged, native machine code. So, what? Now you have to learn how to write complex,
low level code on top of all the complicated game logic you’re already writing? Luckily, the answer is “no”. Thanks to the Unity Burst Compiler, you don’t
have to! Burst is a new math-aware compiler developed
by Unity. It can produce highly optimized machine code
that takes full advantage of the platforms you’re compiling for. It accomplishes this using some pretty sophisticated
technology that utilizes the open-source LLVM project, which handles a lot of the heavy
lifting. And the best part is that it does this all
automatically. All you need to do is add the Unity.Burst
package to your project. Then mark your C# jobs with the BurstCompile
attribute. Once you’ve done that, Unity will take care
of the rest, compiling all of your Unity Job System code into highly optimized machine
code. Now, before you run off to update all your
code, you should keep in mind that the Burst Compiler is still in preview mode. And as of the date this video was posted,
it’s not ready for production. But, that doesn’t mean you can’t get a
head start! Burst is slated to be fully released in 2019
and you’ll want to be ready to take full advantage of it once it’s out. So, thanks to the Unity Burst Compiler, you
don’t need a specialized team of developers that only focus on optimizing your game code. And you certainly don’t need to add complex,
low-level code to the long list of things you need to learn in order to be a successful
indie game developer. All you need to do is leverage this new, amazing
technology and you can easily keep up with the pace of the industry. If you enjoyed this video, please leave a
like and a comment letting me know what you thought. And for more Unity videos just like this one,
don’t forget to subscribe with notifications on. I’ll catch you in the next video!


  1. Very nice explanation! Thanks a lot. I learned quite a few thinks. Subbed.
    Now I look forward to see Burst Compiler and ECS official release.

  2. Great explanation, thanks.
    What about Unity Incremental Compiler
    ? If i just install the package, will it automatically hasten the compilation time ?

  3. I didn't get how exactly they managed to compile into highly optimized code for each platform by Burst compiler. There is already developed technology like bytecode used by Apple where you submit not fully compiled app to AppStore and then when user downloads the app they had compile it according to user's device architecture (armv6, armv7 and so on). Such approach at least helps to not deliver fat binary to target user.

  4. Very interesting. What do you think about the performance gains possible by unity games produced in 5.6 such as Cities: Skylines? A million simulated entities running at 60FPS (which was their goal). They didn't run with il2cpp either, just good old mono and C#. Thoughts?

  5. I'm getting crashes with BurstCompile on the system of one my projects. Have no idea why. Seems to put a limit on the number of entities I can create otherwise it will crash. Maybe all systems have to be Interface Jobs or they won't work together under partial-BurstCompile? It's the only difference to my other projects. Maybe because I'm using ComponentGroupArray which you can't use in an IComponent/Job. But how else can I get the number of entities, or affect them by index? There doesn't appear to be an EntityManager.Length, seems complex just to get the length, or to affect by index. I think it's because Burst is still preview with lots of bugs.

  6. Is char, char[], or string allowed in IComponentData yet cause I'm currently using a "ByteString30" (An IComponentData I made that holds 30 individual bytes…) as a string. And yes, this is a painful, temporary solution.

  7. "the performance of managed code will never come close to that of unmanaged"
    wrong, it can be even faster. Of course in general language without VM is faster, but any bytecode need to be compiled to native code before run it on CPU, CPU can not run it directly. CLR vm compiles it to machine code before run, and it can be compiled more efficient for this concrete platform than code compiled for many platforms one time.

  8. So… Burst is just a repackaged of IL2CPP that Unity have been using for years?

    I truly hate how Unity is pushing ECS so hard. It's just too situational, and have several drawbacks that Unity – and you – usually carefully avoid to disclose.

Leave a Reply

Your email address will not be published. Required fields are marked *