Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Application.LoadLevelAsync Integrate performance

Discussion in 'Editor & General Support' started by ddf, Dec 20, 2016.

  1. ddf

    ddf

    Joined:
    Jul 9, 2011
    Posts:
    54
    I'm wondering the best approach to reducing the time spent in this method. I've managed to reduce it somewhat by destroying objects in the current scene before activating the one I've async loaded, which reduces time spend in UnloadScene. But I'm still seeing three big hits that I'm not entirely sure how to address:

    - GC.Collect is called and eats up the most amount of time with 8% of frame time, but not sure if this is being called explicitly by the this method or if all of the memory allocation here just happens to consistently trigger the garbage collector.
    - UnloadScene > CollectGameObjects > FindObjectsOfType is taking 5% of frame time.
    - FindObjectsOfType, at the same level as UnloadScene is taking 5% of frame time.
    - Loading.AwakeFromLoad, which is where I'd expect the majority of time to go, is only 2% in my test.

    What Type of objects is FindObjectsOfType trying to find here? And does that method inspect *all* active objects in the C# runtime?

    I'm running 5.5.0p2
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    GC.Collect is the garbage collection running. Allocating large amounts of memory can cause that, you should check what allocates memory (during your scene loads).

    FindObjectsOfType is a Unity method that only looks up Unity based objects (things that derive from UnityEngine.Object), so it does not inspect all active runtime objects (in the C# runtime).
     
  3. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    245
  4. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    The manual says "To avoid hiccups we limit integration time on a main thread [...] 50ms"

    But my profiler says: Application.LoadLevel Integrate - Time ms=238.74, Self ms = 70.15

    So... not so great. :)
     
  5. rh_galaxy

    rh_galaxy

    Joined:
    Jan 13, 2019
    Posts:
    8
    Can't the new incremental GC in Unity take care of this - just be leaving the memory to the GC...

    From the game log:
    "Unloading 144 unused Assets to reduce memory usage. Loaded Objects now: 2246.
    Total: 82.161980 ms (FindLiveObjects: 0.188295 ms CreateObjectMapping: 0.040623 ms MarkObjects: 81.442011 ms DeleteObjects: 0.491050 ms)"

    What does gc.markdependencies (MarkObjects) do?