Search Unity

Strange huge ms spikes in the profiler

Discussion in 'Editor & General Support' started by willianbrasil, Jul 26, 2018.

  1. willianbrasil

    willianbrasil

    Joined:
    Oct 17, 2017
    Posts:
    5
    (Unity 2018.1.6) Hello, i'm trying to optimize my game as much as i can since i'm going for android, and i was profiling to see what was causing some slight stutter in my game, and i've noticed these anomalies:

    1) Animator.FireAnimationEvents -> Bat_Info.MeleeHitSound() - 96.32ms

    Code (CSharp):
    1.  private void MeleeHitSound()
    2.      {
    3.          sound.pitch = Random.Range(0.8f, 1.3f);
    4.          sound.Play();
    5.      }
    now, i'm sure that this event has occurred many times before and it was never a problem.

    2) Animator.FireAnimationEvents -> Enemy_Manager.Ranged_Anim() - 19.50m

    Again this script never gave me any trouble, but i've recently noticed some spikes recently that might be because of the way i'm handling my projectiles, but this specific event was NEVER a problem.

    3) Projectile_Manager.OnTriggerEnter2D->Instantiate() - 50.02ms The whole function which instantiated is too big so i'll just post the instantiate code since it seems to be the problem:

    Code (CSharp):
    1. GameObject inst = Instantiate(hit_fx, fx_pos, Quaternion.identity, Game_Manager.gameRescaler);
    Once again it doesn't seem to be something that would cause this high peak, i know instantiate is not recommended, and the best practice would be pooling it instead, but since it wasn't affecting my performance before, i don't believe that pooling would fix this.

    Update: I've tested a bit more, and these errors didn't repeat, but some others appeared like a file.open from transparency geometry, from camera.Render, gave me a spike of 148ms, is this actually happening?
    If this is some error from the profiler itself, then how reliable is the information given by profiler?
    If it's not a profiler error(which i believe it isn't) then why am i getting this sorts of anomalies?
    This is happening almost every time a run my game, from a different source.
    Also my project was made in unity 2017.1.0 and i've recently updated it to 2018.1.6, could this be the cause of the problem?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    This is a bit sparse in information to make concrete assumptions. A repro case or exported profiler data might provide more insights (in the profiler top bar, there's a save button. the saved file can also be zipped to stay under the upload limits for the forum)

    If I had to guess, I'd say the spikes come from having to load sound files/texture files into memory. Maybe look at the import settings for the sounds/textures underneath this? E.g. your Melee hit sound and whatever is part of the hit_fx.

    Potential reasons for this not being an issue before but now:
    - changed import settings / file formats / compression settings
    - a change in how they are imported/loaded into memory
    - you've continuously added content and increased memory usage and now there is too much memory pressure? have you looked at the memory usage chart in the profiler?
     
  3. willianbrasil

    willianbrasil

    Joined:
    Oct 17, 2017
    Posts:
    5
    Hi, sorry for the delayed answer, i've had some health issues and i was searching for the errors you've pointed, indeed that specific sound was with the wrong configurations, at my teleporter i was naively using the animation component, since it had only one animation i thought that would be okay, as for the other peaks i'm being able to figure out why they are happening and managing to work them around, also developing some good practices which i believe that will help me a lot, as for the memory i've debugged it through android studio and it gave me around 110MB during an apk build test. Thanks for the quick answer, if i'm not able to figure out or reduce any specific peak i'll open a new thread for it.
     
    MartinTilo likes this.