Editor loop idle for 30ms in profiler?

For some reason my game slows down like this when I schedule this job.

    [BurstCompile] private struct MovementJob : IJobForEachWithEntity<PathIndex , PlatoonReference , Translation>
    {
        [ReadOnly] public float dt;
        [ReadOnly] public BufferFromEntity<PathPosition> pathPositionBufferFromEntity;

        public void Execute( Entity entity , int index , ref PathIndex pathIndex , ref PlatoonReference reference , ref Translation translation )
        {
            if ( pathIndex.value >= 0 )
            {
                DynamicBuffer<PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[ reference.entity ];

                float3 pathPosition = new float3(
                    pathPositionBuffer[ pathIndex.value ].position.x ,
                    translation.Value.y ,
                    pathPositionBuffer[ pathIndex.value ].position.y );
                float distance = math.distance(
                    pathPosition , translation.Value );
                float3 direction = math.normalize(
                    pathPosition - translation.Value );

                int branch = math.select( 0 , 1 , math.abs( direction.x ) <= 1 );
                float3 value = new float3(
                    direction.x * 30f * dt ,
                    0 ,
                    direction.z * 30f * dt );

                translation.Value += value * branch;

                branch = math.select( 0 , 1 , distance <= 0.3f );
                pathIndex.value -= branch;
            }
        }
    }

Show profiler hierarchy. Which count of entities it processing? Editor loop can idling because of waiting jobs chain completion I guess or waiting GPU. Anyway need to see profiler hierarchy.

To see what’s happening in the EditorLoop, switch the Profiler target from Playmode to Editor. Also, if it is an issue of the main thread waiting for some job threads to finish, that might be more visible in Timeline view, so also check in there what the other threads are doing while the editor is slowing down.

1 Like

I have a similar problem, although this occurs in every project in unity versions 2020 and up.
All render threads and similar seems to be waiting for cpu, and cpu is on “application.Idle” for most of the time.
What it seems to be waiting for is a background worker with the only process to sleep…
Edit: on 2020 LTS this is also quite slow compared to 2019. The Thread sleep is gone but application.idle is still on, but not waiting for anything particular in the threads…

Does this happen during play mode? If not, have you checked the Preferences → General → Interaction Mode?

Same problem… Unity 2021.3.8f1

Default Interaction Mode

Happens in play mode and the game stutters.

edit:

right… now it shows as Application.Tick → … → GameView.DoToolbaGUI() (edit mode, deep profile)