Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Any update regarding "Increased script assembly reload time"?

Discussion in '2021.2 Beta' started by DoctorShinobi, May 28, 2021.

Thread Status:
Not open for further replies.
  1. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    I’m not convinced the problem is object property serialization. I have a small number of objects in my hierarchy at startup. I am interested in understanding what Unity’s plan is to address the regression.
     
    goncalo-vasconcelos likes this.
  2. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    49
    Oh it's not, and that's definitely not what I was implying. I was just listing some steps I took (things I had agency over) to mitigate the long reload times; steps that someone else in my position could try. Again, I got tangible positive results (lower reload times) from migrating the project to an SSD, and upgrading to VS Community edition 2019.
     
    DaemonTrey and stonstad like this.
  3. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    The project-specific optimization tips are appreciated.

    I did want to say, I constantly poke into this issue/thread because it is explicitly about a documented reproducible Regression Bug.

    https://issuetracker.unity3d.com/issues/increased-reload-time

    I've taken so many steps to adjust my project to help with iteration time.

    but no matter what we do, the same exact project will compile->reload faster on older versions of Unity.


    I appreciate the steps the Unity team has taken already.

    I'm posting here in between domain reloads, to add my voice to this issue. This is my number 1 thing I want from Unity--to return to previous version iteration times.

    Imagine being able to code, save, hit Play, and see your changes 5 seconds later, every time. like in the old days.
     
    Last edited: Aug 27, 2021
  4. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    On Monday I think I am going to try to create a reproduction project tailor made for the issue. I am thinking of writing C# code to generate 10,000 C# scripts. The scripts will exist in the project folder but are otherwise not used. This might show it is compilation or app-domain related.

    I'll then benchmark in 2019 LTS, and then 2021.1.18f. Based on ongoing conversations, it seems like this may be a way to clearly demonstrate the issue. If you have ideas and/or suggestions please let me know.

    There is a parallel active thread on this topic (https://forum.unity.com/threads/recompile-enter-play-mode-process.777950/page-2#post-7448198). I have 6K CS scripts, and another dev has 8K, and we are both seeing about 15-45s wait times.

    Separately, the optimization tips are appreciated! My 8-core 4.8 GHz machine with 6 GB/s NVME SSD isn't fast enough for Unity.
     
    DoctorShinobi and Ruchir like this.
  5. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    I dont believe script compilation time is the primary issue, I think many unity devs who understand the assembly reload process understand that the compilation time would be faster today than before. The issue is the domain reload being longer, and also because of the many packages doing many different things that interact with the domain reload process. In the 2017 releases, where UPM didnt exist, the domain reload times were pretty quick however the compilation times werent. Despite that, the overall reload time was still quicker compared to 2021. What helps most from my testing on the overall reload times (not just compilation), were to not use any asmdefs at all, and use the least amount of packages as possible.
     
  6. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    Let us know if you manage to reproduce it, and also if you get an answer from Unity about this regression
     
  7. valarnur

    valarnur

    Joined:
    Apr 7, 2019
    Posts:
    440
    How does domain reload and compilation time change in this test if you have URP/HDRP project?
     
  8. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    So I should try testing with N assemblies, each containing 1K files?
     
  9. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Last edited: Aug 30, 2021
  10. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    It's actually a combination of different things. Compilation time might not be a problem in itself but compilation triggering for just an extra line of comments or a carriage return is something unity could and should avoid. Especially when knowing that domain reloads and stuff is already taking a lot of time.

    Not using packages is well, not an option, each game needs what it needs.
     
    print_helloworld likes this.
  11. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    You could test with the domain reload timings logged. I've found that the burst package has one of the biggest penalties, making urp/hdrp pretty much add 1 extra second because of their dependencies. Of course user code can also be responsible, so if unity serialized the whole game then obviously it would take longer. Though user code serialization should be ignored as that was always something that could make your domain reload times atrocious. You can inspect these times better if you perform a domain reload with deep profiling in editor enabled (though you might run out of ram when inspecting the exact frame). At this point its mostly which combination of packages has the lesser time (hint, 0, which is unfortunate as @TieSKey mentions). Also if the package manager window shows that you have 0 packages, you can still have packages in the project as can be seen in the manifest file, and in the detail domain reload timings log.
     
  12. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    Yep, Burst have some nasty times. Which would be ok if it only triggered when burstable code is modified but unfortunately it's not the case. The project settings window usually takes 500ms to refresh upon domain reload for me (as reported like... 4 months ago in other thread) so closing every window/tab does help.

    .... closing windows and restraining ourselves from using stuff, are we back to windows 95? T_T
     
  13. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    “You can’t improve what you don’t measure.”

    It's all conjecture until we have hard numbers. I'm at the stage of testing with scripts only (no serialization, no object hierarchy) and I haven't gotten to assembly app domain reloading yet. Unfortunately, I can test with only a maximum of 1167 scripts due to this issue (https://issuetracker.unity3d.com/is...count-exceed-the-limit-of-1167-scripts?page=2) in 2021.1.15f1. I am seeing 15+ second delays in the editor when one of these scripts is touched. As indicated above, there may be multiple contributing issues but clearly script count and compilation is a factor. Still gathering data and I'll summarize and report via ticket.
     
    TieSKey and goncalo-vasconcelos like this.
  14. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Sounds like you're running into this: https://issuetracker.unity3d.com/is...cripts-and-project-has-more-than-1000-scripts
     
  15. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Last edited: Aug 30, 2021
  16. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    @LeonardP Wouldn't that negatively impact performance for larger projects, i.e. for individuals that have several thousand scripts?
     
  17. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Gist:
    https://gist.github.com/stonstad/1b9281e3384b7644b34cf5c9ceddb42d

    The enclosed script generates 10K CS files with the first 500 as monobehaviors to work around the issue described by LeonardP. The workflow for testing is 1) create test files, 2) enter playback, 3) touch 1, 10, or 100 files, 4) exit playback. 5) Wait for recompilation and app domain reload.



    By design, the test has no serialized object properties or instantiated objects in the hierarchy.

    Unfortunately, I could not reproduce the 15 to 45 second waits I am seeing in my other project. One thing I tried is adding 5 external assemblies, each containing 1,000 classes with generated scripts referencing classes in these assemblies. It had no impact on performance.

    If my goal was to show the slow down is compilation and app domain reloading only, I am unsuccessful. What I found strange is that out of perhaps a 100 tests, two or three times it did pause up to 45 seconds on compilation of a single script and app domain reload. Similarly, the Visual Studio editor sometimes became stuck in an update loop. But in both scenarios it was rare and hard to reproduce.

    I'm really disappointed that I couldn't isolate it to compilation and app-domain reloads.
     
  18. DoctorShinobi

    DoctorShinobi

    Joined:
    Oct 5, 2012
    Posts:
    219
    Did the generated scripts have serialized fields? Perhaps the slowdown is related to how many public fields are in each script
     
  19. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    OK, thanks to the Iteration Profiler (https://github.com/Unity-Technologies/com.unity.editoriterationprofiler), I identified the cause for my game's slow editor iteration performance. I added a carriage return to a single script, brought Unity to the foreground, and then let the profiler record Unity's iteration process. The V2 AssetDatabase is consuming 6.4s seconds in method ImportAndPostprocessOutOfDateAssets. 60% of my editor iteration time, resulting from changing a single script, is caused by the V2 asset database. This is why my previous testing couldn't reproduce the behavior -- it was not accounting for the size of the asset database in a large or (A)AA project.

     
    UniqueCode, NotaNaN, Ruchir and 2 others like this.
  20. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    @DoctorShinobi

    In the interest of checking if a common thread is the v2 asset database, could you confirm if you are using it for your affected projects? Also, could you report the size of the asset database in your project?

    // size of asset database
    Debug.Log(AssetDatabase.GetAllAssetPaths().Length + " Assets");

    Here's my timing:
    AssetDatabase.V2.ImportAndPostprocessOutOfDateAssets. 22371 Assets, 6488ms
     
  21. kayroice

    kayroice

    Joined:
    Feb 7, 2017
    Posts:
    49
    Quick question for any of you who are experiencing slow reload times - are you using Visual Studio Community 2017 (or maybe even an older version)?

    Just want to reiterate that I am seeing different behavior during script compilation and domain reload after upgrading to VS Community 2019. I suspect that after upgrading to 2019, and migrating to asmdefs for all the code in my project, that 2019 is honoring the asmdefs, and not attempting to reload all the many Unity assemblies when I update my code. In fact, I just checked the date stamps on the assembly csproj files in the root of my project dir, and the csproj files that are specific to my namespace and asmdefs have a timestamp that reflects the last time I updated my code (today) whereas Assembly-CSharp.csproj, Assembly-CSharp.Player.csproj, etc. all have date stamps from a few days ago (not sure what triggered their recompilation - might have been a reimport of my project after downgrading from 2021.1.18 to 2021.1.13 if I remember correctly).

    So for those of you who are suffering, have successfully namespaced their code and/or migrated to asmdefs, but haven't upgraded to 2019, you may want to try the upgrade and see how that affects your compilation behavior.

    If you haven't namespaced and migrated to asmdefs, then it certainly won't hurt to get your code out of Assembly-CSharp*.csproj and see if that results in any gains in compilation and reload times.
     
  22. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
  23. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417


    Several teams at Unity are actually involved at working on this and from our investigations, it seems that it is not related to one particular piece of changes, but more an accumulation of different changes - and sometimes unrelated . For example, we did introduce a new compilation pipeline in 2021.x that was faster on bigger projects - but discovered that it was slower on small projects, while we haven't changed much the compilation pipeline in 2020.x (compare to the changes in 2021.x). So we definitely see what you are experiencing, which is really not great, and we are actively trying to solve this issue.
     
  24. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Thanks @xoofx. Is one of those active bugs the v2 asset database refresh behavior for a single script change? This appears to be 60% of my iteration time in 2021.x.
     
    kayroice likes this.
  25. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Visual Studio 2019 16.9.0
    Visual Studio Code Editor 1.2.3
    Visual Studio Editor 2.0.11
     
    kayroice likes this.
  26. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    ImportAndPostprocessOutOfDateAsset is slow because it calls/contains the domain reload (among other sources of slowness).

    As for the domain reload itself I find Burst dll taking like 1 full second by itself.
     
  27. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    kayroice likes this.
  28. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    stonstad likes this.
  29. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    This is one https://issuetracker.unity3d.com/issues/increased-reload-time that our teams are tracking (there are likely others more specifics), in the scenario of a single C# script change, yes.
     
    NotaNaN, Seith, cxode and 2 others like this.
  30. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @xoofx Just to reiterate that this is a huge workflow hindrance which is affecting all the studios working on larger projects out there. Needless to say it should be a very high priority on you guys' agenda. If that is really not fixed in 2021.2 it will eventually become a deal-breaker.
     
  31. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    I get better results on my 980pro (7000Mbs) than the 500Mbs SSD or the HDD, but the reloading times are huge anyway to get stuck every 1-2 minutes you are testing something in the editor...

    2021.1.19f1 still has this issue. #crying
     
  32. merpheus

    merpheus

    Joined:
    Mar 5, 2013
    Posts:
    202
    Honestly, if you open a small project with 2019 vs 2020. You will notice a huuge difference in loading times. That loading bar is keeping us waiting for a minute or so. I have no idea what have been introduced via 2020+ but that must be solved. Because it is the fundamental part of every day Unity use and it is oddly slow.
     
    emerge-sjh, kayroice, Seith and 3 others like this.
  33. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    It's the case already, It has the highest priority.
     
  34. xxsmbr

    xxsmbr

    Joined:
    Feb 4, 2021
    Posts:
    51
    Having major issues here also - many other devs in the studio have the same problems, if it does not become solved soon it will push towards Unreal. In our cases it simply seems to lock up on reloading script assemblies.
     
    Seith likes this.
  35. RobertOne

    RobertOne

    Joined:
    Feb 5, 2014
    Posts:
    259
    I am still on 2019LTS since the reload times went all downhill since 2020. I am more worried that The LTS support will end in half a year. Do you concider to extend the LTS for 2019 if this isn’t fixed?
     
  36. Tentakero

    Tentakero

    Joined:
    Mar 5, 2017
    Posts:
    17
    I was able to resolve the issue by following advice in this thread in regards to Visual Studio.

    https://stackoverflow.com/questions/34823493/scanning-new-and-updated-mef-components/39454620

    -------------------------
    Particularly this response:
    "I had to delete the contents of %localappdata%\Microsoft\VisualStudio\14.0\MEFCacheBackup as well as %localappdata%\Microsoft\VisualStudio\14.0\ComponentModelCache"
    -------------------------
    I was using VisualStudio 2019 v16.11.2 and the only difference was the version number folder. Unity version is v2020.3.11f1. Went from 5-10 minute script reload time to the standard 3-5 seconds or so. The issue hasn't happened again but I'm keeping an eye on it since I'm not sure if this will work for others.
     
  37. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    You should create a bug report with ideally a small repro. It is likely that it has nothing to do with iteration time but some code (e.g experimental packages) that is keeping a file open on some .NET assemblies. Without a repro, we can't tell if it is something wrong on your side or directly from something within Unity.
     
    mahdi_jeddi likes this.
  38. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    blank projects with a single script still have this issue... it's way worse on MacOS M1 + 2021.1.20f1...

    I love Unity but dunno why everything beyond 2020.1.17f1 is that slow...
     
  39. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    Not working on my end. Still same reloading time with latest version from VS Installer
     
  40. xxsmbr

    xxsmbr

    Joined:
    Feb 4, 2021
    Posts:
    51
    Does not matter if its a huge project or new one, it happens. Just create a new project and bingo. issue.
     
  41. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    We haven't been able to reproduce such a problem, so we need more input from your side. Could be a machine issue, anti-virus or something else. If that was so obvious, a lot more folks would complain about this issue, much more than iteration time (we would have also this issue when simply using Unity during our tests, which does not happen)
     
  42. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    weird to read that when you can see so many people here with the same issue on different platforms... :/
     
    StellarVeil likes this.
  43. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    @stevejohnnicholls is talking about a lock of a file that is blocking the editor. The iteration time is another problem that we are well aware and many teams at Unity are working on this.

    But, for example on your issue, you mentioned M1, that could be a very different issue also as well (e.g generated JIT code for M1 not well optimized)

    The more the issue is specific, reproducible (with a bug report) and comes with numbers, the more we can help and try to fix them.
     
    mahdi_jeddi, stonstad and LeonhardP like this.
  44. lawsonh

    lawsonh

    Joined:
    Jul 25, 2018
    Posts:
    80
    Is 2020.1.17 faster than 2021.1 on M1?
     
  45. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    Actually yes. In big projects the busy/delay time increases a lot in 2021. 2019 is the fastest (by far) tho.
     
    lawsonh likes this.
  46. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    That's reassuring news. I'm hoping the bar is high -- we need to return to subsecond iteration for script-only changes.
     
  47. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    You guys should check out the alpha in regards to the iteration times, just sayin. Rumours say it might be a bug.
     
    FernandoMK and KamilCSPS like this.
  48. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Better or worse, and by how much?

    *update.

    Domain reload may be disabled in the build you tested (https://forum.unity.com/threads/what-is-happening-with-this-alpha.1167083/). Not an option for me for playback but happy for those that can disable domain reloading. Hoping complete domain reload is skipped with script changes.
     
    Last edited: Sep 16, 2021
  49. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Did you try Apple silicon 2021.2 builds? They should be pretty fast on M1 devices.
     
  50. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    I wish we will be able to go under subsecond, but it will be difficult to bring this immediately! :) The reason is that over the years, Unity has been growing with more new features and so with more code running at initialization time. Re-architecturing initialization is not something easy, specially when a large part of the engine requires the code to run on the main thread or that very few APIs are async friendly.

    Our short term goal is to try to come back around 1s to 2s on a script change (involving only one assembly) by optimizing existing initialization code paths. We want also to add more safe guard in our CI to track this kind of regressions.
     
Thread Status:
Not open for further replies.