In my systems I use ECB's in the standard sort of way. I use a cached EntityCommandBufferSystem to create a new command buffer, pass it to the job and call AddJobHandleForProducer with my job's handle.
I noticed that disposing these ECB's is taking up a lot of time.
Here's an example where 45 of my systems in this group are taking almost a whole ms to dispose their ECB's. If I drill down with the deep profiler, it's apparently calling Array.CustomResize 3,117 times in the dispose call, which seems... wrong?
This is Entities 1.0 pre.15. And you can see it occur in the game on an empty map where the player has not done anything.
This appears to be the code responsible in EntityCommandBuffer.cs. The resizes might be expected, I just wanted to raise a post because it seemed a bit sus.
// Arrays of entities captured from an input EntityQuery at record time are always cleaned up
// at Dispose time.
var entityArraysCleanupList = chain->m_Cleanup->EntityArraysCleanupList;
while (entityArraysCleanupList != null)
{
var prev = entityArraysCleanupList->Prev;
Memory.Unmanaged.Free(entityArraysCleanupList->Ptr, m_Data->m_Allocator);
entityArraysCleanupList = prev;
}
chain->m_Cleanup->EntityArraysCleanupList = null;
Memory.Unmanaged.Free(chain->m_Cleanup, m_Data->m_Allocator);
while (chain->m_Tail != null)
{
var prev = chain->m_Tail->Prev;
Memory.Unmanaged.Free(chain->m_Tail, m_Data->m_Allocator);
chain->m_Tail = prev;
}
chain->m_Head = null;
if (chain->m_NextChain != null)
{
FreeChain(chain->m_NextChain, playbackPolicy, didPlayback);
Memory.Unmanaged.Free(chain->m_NextChain, m_Data->m_Allocator);
chain->m_NextChain = null;
}
(CreateCommandBuffer calls I mean)
