Blocking mode DispatchPairSequencer waste too much time!!! Unity official staff please come in.

In my program, I found that in worker13(not fixed) of Timeline, there is something called “DispatchPairSequencer:CreateDispatchPairPhasesJob(Burst)” (it belongs to Unity.physics). It took 16.94ms, which doesn’t matter. But the other 14 worker jobs are all waiting at this time, and almost all threads are Idle (16.96~17.01ms), which is too wasteful!
Can Unity make this Dispatch parallel? Or after this “Dispatch” assign it once, don’t assign it again, okay? This blocking Dispatch causes all other threads to wait, which is too bad!!! The more threads in this way, the more total time are wasted! ! !
And anorther one “DispatchPairSequencer:RadixSortPerBodyAJob(Burst)” is same, it cost average 4ms. So these 2 functions block total 21ms every thread. You know in my program cost 46~50ms per frame. if I can use these 21ms, my frame rate maybe can double!!!
So, who can tell me what is this, official manual doesn’t describe! And how can I improve it by myself. Thanks a lot.

From memory this job is actually setting up the parallel processing for the rest of physics.

Are you profiling this with safety, integrity checks and jobs debugger turned off?

Yes, I “Allow ‘unsafe’ Code” in Porject Settings.
And I found something maybe helpful for Unity, I will write later. (busy now)

That’s have nothing with safety checks, integrity checks and debugger.

Yes I tried, there’s no any effect.
And I will share the thougts about this API: Class DispatchPairSequencer.

Actually my program is based on Unity’s “EntityComponentSystemSamples…-050”. Specifically is Demo: “5d. Change Velocity”, of course I did a lot of different other physics operations and implementations.
In my case, I generated 20,000 entities (around 20~25 frames), and each entity can accept key operations at the same time, for example: each entity can be displaced by friction instead of setting a displacement.
During this process, I found that my 14 threads were in the idle state for a total of about 21ms. The reason is RadixSortPerBodyAJob (4ms) and CreateDispatchPairPhasesJob (21ms). I also checked the manual on the official website (Class DispatchPairSequencer | Unity Physics | 0.51.1-preview.21) but it says nothing!

The first part is my premise, and the latter part is some kind of “suggestion” of mine.
When I generated 20,000 entities, I found that in a general system, it is impossible to use ForEach() to create entities (not allow “Structural changes”), and using ECB will also give up because of many problems that cannot be implicitly converted(ref T). I had to give up generating 20,000 entities in parallel because that would make the program completely stuck for the first 12 seconds of initialization (rough stats). But I still solved this problem very well, and it only took about 1 second to initialize 20,000 entities, and the operation of the whole program did not appear to be completely stuck! (indeed now my program initial 20k with 110fps)
My approach: Created another 9 “Dynamic Spawners” in the Editor, and each “Dynamic Spawner” spawned 2000 entities. The idea came to me while tracing the code in “SpawnRandomObjectsAuthoring.cs”.

protected override void OnUpdate()
    {
        using (var entities = GetEntityQuery(new ComponentType[] { typeof(T) }).ToEntityArray(Allocator.TempJob))
        {
            for (int j = 0; j < entities.Length; j++)
            {

Look, “entities.Length” is actually 10 spawners. Except for some Job Entities and Scene Entities generated by the system, all the entities I want to generate are in those 10 spawners. I don’t know how the “protected override void OnUpdate()” function works behind, anyway, it turns each entities[j] into parallel Jobs! This is why the initialization that originally took 12 seconds with freeze, after I adjusted it, it only tooks 1 second, and it could reach 110 frames in a short time!

My guess is: The bottom layer of DOTS allocates a parallel Job for each entity root (I call each entity[j] as “entity root”) for processing. This greatly reduces the initialization time.

So in the same way, now I have 20,000 active entities, and they may indeed have to use “DispatchPairSequencer:CreateDispatchPairPhasesJob” in each frame of my operation. However, Unity, can you learn from that, I use “Entity root” The method of initialization, do not let this API work in a blocking mode(even though it has to be blocking mode, it still block 15 threads 1 sencond is better than 15 senconds in 1 thread!), but let them be allocated to each Job to run independently? I know, the biggest problem is: Unity don’t know which entities with this API should access?

My suggestion is: at the beginning we assign a large number of entities to different “entity roots”, and then this api is only responsible/operated for that root(single Job), isn’t it good? ! I think the key point is: EntityQuery.

Finally, if in a generic system to initialize and create entities in parallel, just done like I did. All I can say is: I’m sorry, I don’t know that. However, the official Demo of Unity didn’t do this too. ^^


Hello, Unity staff, anyone, say something about this Class DispatchPairSequencer. Can unity optimize this class from single Job’s blocking mode to parallel Job’s non-blocking mode?

No one agree with me?