How to reduce render batches like Official Sample Boids

Hi.
I have a demo to test DOTs code, it goes well.
But there are more render batches(more instance call in FrameDebuger) than official sample Boids’s even Sample Boids has much more Tris and instance data .
I have no idea what happened and need help. Thanks.
Here is a picture:

For starters, why is your number of vertices more than double? This seems odd.
Despite this, your cpu and gpu time indicate your scene is actually more performant. You also have less SetPassCalls, which are the more taxing Draw Calls/Batches, so that is great!

The overhead of draw calls has been improved over time by Unity. It seems you also get a nice performance boost from DOTS as well.

I’d worry less about the batch numbers and more about specific performance bottlenecks, should you encounter them.

2 Likes

Thanks for your replay.

The mesh is Unity default Cube mesh, It has double vertices indeed:)
In DOTs Hybrid batch can reduce SetPass call. for more information :
https://discussions.unity.com/t/803948

There are 50000 fish instances and huge amount Tris and Verts in the Boids Sample runtime, low batch number for Hybrid Batch function i knonw, but it’s not same effect in my demo, it confuses me. In the further it could be a problem when lots lots of Units appear in project.

DOTs is perfect. Later DOTs Animation,Physics code will be tested too .

I got the reason about the difference of batch number between two samples.
Official Sample Boids initialize all unit instances once a time:

var world = World.Unmanaged;
                var boidEntities = CollectionHelper.CreateNativeArray<Entity, RewindableAllocator>(boidSchool.Count, ref world.UpdateAllocator);

                Profiler.BeginSample("Instantiate");
                EntityManager.Instantiate(boidSchool.Prefab, boidEntities);
                Profiler.EndSample();

My Sample initialize a unit instance per a given time:

float time = spawn.ValueRO.Time + deltaTime;
            if(time < spawn.ValueRO.InterTime)
            {
                spawn.ValueRW.Time = time;
                continue;
            }
            state.EntityManager.Instantiate(spawn.ValueRO.Prefab);

            spawn.ValueRW.Time = time - spawn.ValueRO.InterTime;

Initialize entities frequently cause structure change propblem,
it seems no problem to the unit archetypes chunk number, Dose it make some trouble to Hybird Batch Strategy?

Entities Graphics adds Entities to batches when they are first encountered, and does not currently attempt to merge batches that have already been created. If you are creating Entities over time, this can mean that you will end up with more batches than what you would get if you added all the Entities at once.

If you want to, it should be possible for you to manually force Entities to be rebatched again. This can be done by setting the EntitiesGraphicsChunkInfo chunk component to default for any chunks of Entities that you want to re-batch. It’s also possible to do the same by removing the chunk component, but this will cause some structural changes so it’s less efficient.

Based on your screenshots, it looks like your batches should still be well utilized (Chunk Capacity is high, Unused Entities is low), so I would expect CPU rendering performance to be good even with the increased batch count, as the draw calls are likely to have high instancing counts.

Thank you JussiKnuuttila, It’s very clear now.
I will try the re-batch method to deepen my understanding. :):):slight_smile: