Are all OnUpdate() default Burst Compiled?

Pretty n00b question but I am confused about what is and isn’t Burst compiled automatically and where to set it.

If I have:

ExampleSystem : SystemBase
{
OnUpdate()

Entities.ForEach(()=>{}).Schedule()
}

  1. Is the entire system burst compiled by default?

In some samples I see [BurstCompile] above the OnUpdate() function.

  1. Does this mean the containing .ForEach() is also Burst compiled? Or does does the .ForEach() also need to have .Schedule().WithBurst() included?

  2. Is there some global flag where I can say “burst compile everything unless told otherwise”?

None are. Although some might be in the next release according to the 0.17 release notes that are shared.

Should elaborate on that for people.

The interface ISystemBase is being introduced that can be used with unmanaged systems allowing the update to be burst compiled.

4 Likes

@tertle sorry for being annoying but does that mean currently (0.16) the OnUpdate cannot be burst compiled? If so, what is up with the [BurstCompile] decorators I see above some of the OnUpdate()'s in the samples?

It can not. You’d have to show me an example as I’ve never seen what you’re saying.

I should also say that you can burst compile specific methods using function pointers which require them to be decorated with the burst attribute.

1 Like

@tertle you were right I got mixed up :frowning:

https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/ECSSamples/Assets/HelloCube/2.%20IJobChunk/RotationSpeedSystem_IJobChunk.cs

The [BurstCompile] decorators are meant for Job structs only.

It looks like each .ForEach() needs to be appended with a .WithBurst() for it to be burst compiled.

Nah that’s not required. Entities.ForEach in SystemBase are automatically burst compiled unless you add WithoutBurst or WithStructuralChange. The WithBurst option just allows you to pass extra params such as CompileSynchronously or FloatMode etc.

2 Likes

@tertle do you know if Job.WithCode() is default burst compiled?

The documentation doesn’t say: https://docs.unity3d.com/Packages/com.unity.entities@0.7/manual/ecs_job_withcode.html

All codegen lambdas default to Burst-compiled.

Thank you @DreamingImLatios !

@adammpolak Also, you can always check the Postprocessed IL code in DOTS > DOTS Compiler > Open Inspector… – you’ll see that the generated IJobChunk has a [BurstCompile] attribute:
6680083--765580--Screenshot 2021-01-02 at 17.33.09.png
(And won’t have it if you use WithoutBurst() on the ForEach)

1 Like

Much appreciated!

1 Like