Is using Burst as simple as checking a box?

Sorry for all the questions but im looking for the “for dummies” answer, because its been on my radar for a few years and I just read the blog post about Burst but I don’t really understand it.

Do I just install a Burst package and then click somewhere to compile with Burst instead of unity’s built in compiler?

Or it looks like it doesnt support Classes? So most of my code which uses mono behaviour or when I make new classes, non of that would compile?

So it requires a new type of coding using only a subset of C#? And as long as you follow that you will have more optimized code that runs faster? And is this subset well known and popularly used by many coders?

Finally, if it doesn’t support classes, aren’t classes a fundamental part of most coding languages so isn’t that a big deal id it doesn’t support them?

1 Like

Burst works on jobs Unity - Manual: Job system (or more advanced burst compiled function pointers)

And it does not work on managed objects (classes). This is usually the hardest thing for people to wrap their head around as it requires a different mindset to the more traditional OOP that people have been working with.

Here you can read through what is supported and why:
https://docs.unity3d.com/Packages/com.unity.burst@1.3/manual/index.html

In a nutshell, no, classes aren’t supported and classes aren’t real from the standpoint of code execution on the CPU. Burst compiler is making your code more streamlined to SIMD (single instruction multiple data), which tightly connected how the CPU works and how the CPU fed with the code to run and the data run the code on.
Classes and reference types in general have nothing to do with SIMD since they involve random memory access.
You can read more on the link above. Some method calls are okay.

The subset you can use is widely used and used all the time. By everyone. And it is not new by any means. The trick is to form your code to use them as much as possible without using other things in the middle.
You can use classes (you have to, really) to fire up the Jobs you can vectorize though.

Thank you. I have to admit I’m shocked about the no classes. For the average designer who is not a hard coder this is a big deal, and I’m surprised it’s not mentioned often and always In the more mainstream marketing posts. It’s probably one of the first things I would mention and I think i understand the resistance to dots more now, because I think the vast majority of non hard coders is use to using classes to structure their work.

3 Likes

I can’t find the name of this c# subset. Does anyone know what it’s called?

it’s a very understandable reaction. But there are a few hard truths that most users here have internalized:

  • OOP implies random memory access. By its nature, it’s unoptimized for CPUs and the way they cache data. Data-Oriented, ECS code involves mostly linear access of small blocks of memory, which means it can be highly optimized around CPU caching. For that reason, Data Oriented Design will always have a performance advantage over OOP at medium/high object counts. Often a massive one.

  • Single core CPU speed increases y-o-y have plateaued. But y-o-y advancements in multi-core CPUs is steady. So for the foreseeable future, the future of performance gains means multithreaded code. And the more multithreaded code, the better - gameplay code included.

  • Writing multithreaded, DOD code allows for some pretty amazing compiler optimizations, which is what lead to Burst. The speed increases can be so massive, that ultimately it’s been worth it to make the (occasionally confusing) transition to writing code this way.

Most people in these forums are on the other side of that transition, and believe me, it’s worth it. The only real downside the jumping in now is that it’s not ready for production use (missing features, api still evolving). Though that can also be a great time to learn about it, depending on your circumstances.

However, I should say that Burst is ready for production use. It’s mostly the ECS code that’s still in flux.

3 Likes

https://docs.unity3d.com/Packages/com.unity.burst@1.3/manual/index.html

https://www.gamedev.net/blogs/entry/2265481-oop-is-dead-long-live-oop/

5 Likes

Burst is such a limited product it benefits nobody. except a small set of kids that make test projects for fun.
Meanwhile if you make an actual game with Monobehaviours, use the mathf and Vector3 stuff it doesn’t inline in mono, nor il2cpp it doesen’t use vector math and is basically the way most games are build. hilarious.
Oh… and in mono all floats are treated as doubles and casted to and from doubles to floats all the time incurring heavy costs for no reason… :smile:

2 Likes

Can we not turn this into a DOTS hate thread?

The purpose of Burst is to target a specific subset of the codebase and with additional knowledge of aggressive assumptions it can make, compile the code way more optimally than any general-purpose compile can. It also provides tooling and resources to customize and tune this behavior and report when things don’t go quite right.

6 Likes

Great article. I stand corrected - not all ECS code is faster than all OOP code. I would be curious to see an updated comparison with newer DOTS code, Jobs, and Burst, vs optimized OOD code + Jobs and Burst (being serious here - no sarcasm).

What I said is true: Linear access across a single cache line will always be faster than random access that requires fetching. It’s the same as saying time-to-fetch > time-to-not-fetch.

In general, though, ECS really does have many performance, maintainability, and organizational advantages to DOD code. Come drink a little Kool-aid and find out. :slight_smile:

Be careful. The article is misleading. What the guy is actually doing is building what I typically refer to as an Object-System architecture. I provide a little bit of insight about it and other architectectures here: ESC API vs Other DOD API

The original topic of this post is Burst, which is architecture-agnostic. @protopop Is there a particular piece of code that is performing slow that you would like to optimize? Perhaps a particular piece of code that uses the keywords “while, for , or foreach”?

2 Likes

Hard disagree. It has helped our game in early access tremendously. Some devs in this forum are using it in their games in development.

8 Likes

I’m interested in a link to the project/steam store?
Where did you use Burst in your project and it proven to be needed for your projects requirements? and this was not obtainable in another way?

I think my frustration stems from the fact that most Unity API by itself is not performant, or accessible from Jobs/Burst.
And the current API available is bogus and performs bad because nobody in Unity seems to care about performance of their CS code or math library.

Performance by Default? lies.

As example take the simple case of you want to run a raycast. We all know that mono does not inline… and that mono is slow with method calls cause it looses context and cache. and that calls to native are heavy. SO lets see what it does.

Will you come on this journey with me?

    public static int RaycastNonAlloc(Vector3 origin, Vector3 direction, RaycastHit[] results, [DefaultValue("Mathf.Infinity")] float maxDistance, [DefaultValue("DefaultRaycastLayers")] int layerMask, [DefaultValue("QueryTriggerInteraction.UseGlobal")] QueryTriggerInteraction queryTriggerInteraction)
    {
      return Physics.defaultPhysicsScene.Raycast(origin, direction, results, maxDistance, layerMask, queryTriggerInteraction);
    }
  1. So Physics.defaultPhysicScene is a Method call, and it does a call to native of getting the current/default physics scene.
  2. Raycast is a call.

Lets look on!

      return (double) direction.magnitude > 1.40129846432482E-45 ? PhysicsScene.Internal_RaycastNonAlloc(this, new Ray(origin, direction.normalized), raycastHits, maxDistance, layerMask, queryTriggerInteraction) : 0;
  1. direction.magnitude is a method call. it does:
return Mathf.Sqrt((float) ((double) this.x * (double) this.x + (double) this.y * (double) this.y + (double) this.z * (double) this.z));
  1. mathf.Sqrt is simply a return float casted double Math.Sqrt
  2. Math.Sqrt in itself is a method call > to native instrinct
  3. Then we do Create new Ray Struct. we pass it a direction.normalized. that is a method call!
    lets look at it!
get { return Vector3.Normalize(this); }
  1. yeah that is another one…
float num = Vector3.Magnitude(value);
      return (double) num > 9.99999974737875E-06 ? value / num : Vector3.zero;

10!. Hey how cool, we do a Magnitude again. so lets add 3
11 or 12. If returning Vector3.zero it is a method call. ({get return zeroVector} else if value/num we get. function call to operator overload of / which is return new Vector3(a.x / d, a.y / d, a.z / d); another method call :smile:
13. new Ray == methodcall.
Inside the Ray struct constructor we have… you guessed it…

   this.m_Origin = origin;
      this.m_Direction = direction.normalized;

Another Normalize! :smile:
so lets add another 5.
So final count is 18 method calls, 3 sqrts a bunch of float to double and double to float casts and calculating magnitude 3 times and normalizing twice.

This is a simple RANDOM case.

Why nobody solved this? why nobody seems to care?

Mono does not inline, il2cpp also not, or almost never. Even with aggressive inlining applied (not applied in any unity libs) and even if it would be inlined, in Il2cpp it adds a bunch of static bools to every method in static classes to check if they have been initialized yet…

Performance by default.
Maybe… if you don’t use any part of unity.

11 Likes

You do understand that they’re making whole new APIs for DOTS, right?

It’s nonsense to bash DOTS and the Burst compiler while pointing at the old stuff that’s largely unrelated. The bridges they’re making (like the meshData stuff) are meant to ease the transition and fill the holes until native DOTS systems are developed.

The whole point of this motto is that they’re making new stuff with performance in mind. I honestly can’t understand your rant.

Fixing this stuff is easy, just put a single coder a week on manually inlining everything and you have a more performing Unity for everybody, no burst needed. Speedup of that is between 2 to 3x on all math.

That was my point, burst is useless tech used by a select few, and most things are not available or WIP. whilst the thing that is used by many is not fixed. frustration galore.

6 Likes

Look, I have no intention of further derailing this thread. I’m just gonna say that what your asking for sounds reasonable but is largely unrelated to the topics where you usually ask it.

Both you and unity have seen the same problem and they’ve decided to solve it in a particular way. Whether you like it or not, they’re already invested in it and they will not halt it or throw it away (as you’ve asked for in the .NET 5 thread).

At this point, it’s better to be constructive and try to help the new tech be as good as it can because like it or not, it is the future of unity. They will not touch the mathf library. They won’t risk introducing bugs, because they’ve moved on. I suggest you focus your (valid btw) criticism into something they’re willing to work on.

3 Likes

I wish I had kept my mouth shut, and just responded to technical questions. My apologies, protopop.

2 Likes

For instance? The exact words that are misleading?

The article is technically accurate, and the gist of it is that it’s up to you to approach the programming paradigm where one person approached it in a bad way, and the other one re-structured it to make it fast and efficient. When you call it an Object-System architecture is just one of the possible forms, but not the only one that OO allows you to do, that’s the point.

1 Like

No apologies. You sound really reasonable and knowledgeable, and you share it on a friendly non threatening way.

I do think the no classes thing will be too esoteric for casual coders like me raised on JavaScript and c#. For me the important thing is to better understands what dots, Ecs, burst etc are because after several years I don’t really get it.

Part of that I think is the messaging because I think if it doesn’t support classes I would mention that way up front, I mean I had never heard of that, so when I find it out after digging only it makes burst seem even more inaccessible, not because you can’t use classes; but because the marketing around it doesn’t make this very clear to new people wondering what it is all about. If we just say “you can’t use classes but wow it’s performant in x case” then we can digest the good with the bad (bad being learning a new coding paradigm which is a resource sink even if it is helpful). When the pr has only the positives on the surface I began to wonder why am I not using this, so when I find out the challenges are not presented up front I get it but I think it would actually help to be more transparent. It would be good to know we need to learn a new way of coding actual code and that this code is part of c#.

The other issue is No one seems to know the name of this c# subset. Someone posted a link to the burst page before but I didn’t see the name. It HAS to have a name doesn’t it? How can we communicate burst to people without information like this. We can’t just say it usesba c# subset because there are infinite possible subsets right? And this is a particular subset correct? I’m not trying to be facetious but I’m legitimately curious - I mean is it called like “c# simple set” or something, anything. Things like this make it really difficult for people like me to understand what is required and what is going on . I’m still hoping someone can tell me the name of the subset, because I think it was mentioned lots of people are using it so it must have a name.

This thread is very illuminating too about some of the benefits of oop vs dots and the strength of each and why some things are faster or slower so I definitely have some more insight I think after reading all this.

EDIT: if it doesn’t already exist I vote to call the subset “CSharp Strict”

3 Likes