NativeArray.SortJob() is slower in build than in editor

Is there some explanation for this? Maybe I’m using it wrong or something.

It’s a generic method scheduling a generic job. Burst only works in the editor for that use case. You have to use some trickery to get Burst to work in a build.

Oh shoot. You are right! The one in build is not Burst compiled.

What trickery can I apply here?

You can explicitly create instances of the generic jobs the generic method uses somewhere random in the code so that Burst sees it. Or you can use some codegen to trick Burst.

I see. Nevertheless, I see this as a UX issue. How come it Burst compiles on editor but not on build?

I tried to copy the method used in my system class to use the explicit item to sort but the struct jobs used are not public. If I copy those struct jobs, it uses all the other methods found in NativeSort.cs. I don’t like this as I had to copy the whole thing for each type that I’d like to sort.

I’m not sure how to do this. I tried this but I think it’s wrong:

JobHandle handle = inputDeps;

this.Job.WithCode(delegate {
    entries.SortJob(handle);
}).Schedule();

My solution (in the next release which is taking a lot longer to stabilize as I have also been working on a game) does not cover this particular use case. So I recommend the other solution for now.