Hello, I’m having a bit of trouble understanding something about the profiler:
I’m trying to understand why my worker threads are idle so often. Apparently the 3 workers I have are idle for a total of 28.30ms. What a waste of time! So what can causes that exactly? Almost none of my jobs have any .Complete() statement, except the ones that depend on player input, but those ones aren’t in the screenshot. The systems who do have to .Complete() every frame hardly do any main threaded work, maybe a couple if and elses. The render system in addition has to do some memcpys, but that’s about it.
Most likely because the work on your main thread is taking longer than the work in your jobs. You can see all your systems taking longer to execute than the jobs themselves.
Is there any way to find out where though? Deep profiling the code only shows a huge mess of calls that ultimately lead to jobs, not to those little idle sections shown in the timeline.
If you want to test main thread performance of parts of your code, add your own Profile blocks; it’s what Unity does on their systems.
Snippet from RenderMeshSystemV2
Profiler.BeginSample("Sort Shared Renderers");
var chunkRenderer = new NativeArray<int>(chunkCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var sortedChunks = new NativeArraySharedValues<int>(chunkRenderer, Allocator.TempJob);
var gatherChunkRenderersJob = new GatherChunkRenderers
{
Chunks = chunks,
RenderMeshType = RenderMeshType,
ChunkRenderer = chunkRenderer
};
var gatherChunkRenderersJobHandle = gatherChunkRenderersJob.Schedule(chunkCount, 64);
var sortedChunksJobHandle = sortedChunks.Schedule(gatherChunkRenderersJobHandle);
sortedChunksJobHandle.Complete();
Profiler.EndSample();
var sharedRenderCount = sortedChunks.SharedValueCount;
var sharedRendererCounts = sortedChunks.GetSharedValueIndexCountArray();
var sortedChunkIndices = sortedChunks.GetSortedIndices();
m_InstancedRenderMeshBatchGroup.BeginBatchGroup();
Profiler.BeginSample("Add New Batches");