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

Going into Play Mode is slow(er than we'd like)

Discussion in 'Editor & General Support' started by milchoDH, Sep 30, 2018.

  1. milchoDH

    milchoDH

    Joined:
    Jun 17, 2017
    Posts:
    4
    Salut,

    As our project grows we're experiencing higher and higher overhead on the compile and going-into-play-mode actions. I've been doing some marginal profiles and testing recently to try and narrow down on the culprits. I did manage to get going-into-play-mode time down quite a bit, but I feel there should be more room for improvement.

    For reference, it takes me between 5-6 seconds to go into play mode with:
    i7 6700k
    32GB RAM
    M.2 1400MB/s SSD
    GTX 970 (largely irrelevant for this I assume)

    I also have a laptop, which takes around 10 seconds to go into play mode with:
    i7-7700HQ
    16GB RAM
    SSD
    GTX 1070MQ

    There are a few things in the profiler that I am not sure I understand. Let's start with a non-deep profile on the laptop:


    This is the first thing that caught my eye when profiling - a big chunk (~5) of the first 9 seconds are spent in ReloadAssembly (1/4th of which is in executing the OnLoadAttribute)

    To get more info let's look at the deep profile:


    The first strange thing on this snapshot is that the [Time ms] are not shown in the majority of the stack trace. I assume that's either a limitation of the profiler or a bug. In either case, that's not terribly useful as an absolute metric in deep profile - it's mainly useful to locate the bottleneck. I used the GC Aloc instead, which works in this case.

    Looking at this stack trace I also feel a bit worried - you can see CreateDefaultEncoding() opening a FileStream, which eventually loads in all Editor Assemblies. Let's not go into that though - just looking at the bottleneck, it seems that RegisterAssembly() is really what eventually ends up eating a lot of that time (by using some good-old reflection) since it's called 331 times.

    This is no surprise, but I am trying to make things run faster, so I ask if anyone has any ideas on how to improve this situation? For instance, why is the profile detecting 2 calls to AssemblyUtilities.Reload()? I put a breakpoint in that method and was able to extract a list of all of our assemblies:

    Am I missing something here or is this a cost we have to take?
     
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Hi!
    Incomplete calls hierarchy with the deep profiler case is more likely caused by max used memory limitation we have for profiler. Which version of Unity do you use? In 2018.2 there is a way to control it from commandline (-profiler-maxusedmemory 500000000) with 256MB by default.
    From a capture I can say that the culprit is more likely WwiseSettings.LoadSettings. I would inspect in ILSpy what is the method doing.