Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor loop idle for 30ms in profiler?

Discussion in 'Entity Component System' started by MintTree117, Apr 1, 2020.

  1. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    For some reason my game slows down like this when I schedule this job.
    Code (CSharp):
    1.     [BurstCompile] private struct MovementJob : IJobForEachWithEntity<PathIndex , PlatoonReference , Translation>
    2.     {
    3.         [ReadOnly] public float dt;
    4.         [ReadOnly] public BufferFromEntity<PathPosition> pathPositionBufferFromEntity;
    5.  
    6.         public void Execute( Entity entity , int index , ref PathIndex pathIndex , ref PlatoonReference reference , ref Translation translation )
    7.         {
    8.             if ( pathIndex.value >= 0 )
    9.             {
    10.                 DynamicBuffer<PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[ reference.entity ];
    11.  
    12.                 float3 pathPosition = new float3(
    13.                     pathPositionBuffer[ pathIndex.value ].position.x ,
    14.                     translation.Value.y ,
    15.                     pathPositionBuffer[ pathIndex.value ].position.y );
    16.                 float distance = math.distance(
    17.                     pathPosition , translation.Value );
    18.                 float3 direction = math.normalize(
    19.                     pathPosition - translation.Value );
    20.  
    21.                 int branch = math.select( 0 , 1 , math.abs( direction.x ) <= 1 );
    22.                 float3 value = new float3(
    23.                     direction.x * 30f * dt ,
    24.                     0 ,
    25.                     direction.z * 30f * dt );
    26.  
    27.                 translation.Value += value * branch;
    28.  
    29.                 branch = math.select( 0 , 1 , distance <= 0.3f );
    30.                 pathIndex.value -= branch;
    31.             }
    32.         }
    33.     }
     

    Attached Files:

  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    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.
     
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    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.
     
    MintTree117 likes this.
  4. Estemyr

    Estemyr

    Joined:
    Oct 9, 2018
    Posts:
    8
    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...

     
    Last edited: May 13, 2021
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Does this happen during play mode? If not, have you checked the Preferences -> General -> Interaction Mode?
     
  6. MrCool92

    MrCool92

    Joined:
    Jul 13, 2015
    Posts:
    26
    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)
     
    Last edited: Dec 14, 2022