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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Official Improving iteration time on C# script changes

Discussion in 'Scripting' started by xoofx, Oct 18, 2021.

  1. StellarVeil

    StellarVeil

    Joined:
    Aug 31, 2018
    Posts:
    60
    I just tried the latest 2022.2 beta which has that issue fixed but no improvements whatsoever to iteration time sadly.
     
    TangerineDev likes this.
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,707
    My experience with a project that is 25GB in size with well over 3000 scripts is that reload script assemblies takes about 2 seconds after hitting play and total time waiting after editing a script is about 4 seconds.

    So, for whatever reason, I don't seem to be affected by the same problems that are being reported here.
     
    Niter88 likes this.
  3. pastaluego

    pastaluego

    Joined:
    Mar 30, 2017
    Posts:
    140
    What unity version?
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,707
    Version 2022.1.19.f1
     
  5. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    164
    I use Jetbrains Rider and found that removing the two visual studio packages (don't need them) made a big difference. As an example, opening Unity on a project took 32 seconds until I removed the visual studio packages. Now 15 seconds. Assets folder size about 2 GB. Transitioning to play from edit mode also improved dramatically. Wild.

    System: 12900K @ 5 GHz. 32 GB DDR5/5200 MHz, NVME Samsung 980Pro on MSI Z690 Carbon

    I'm wondering if the Visual Studio packages are from Unity or provided by Microsoft.

    I've never understood why the Visual Scripting package is a default install. I end up having to remove it every single time. I don't mean to offend anyone (and do not want to derail this valuable thread) but I can't imagine why any experienced dev would use it.

    BTW this is on Unity 2022.1.16
     
  6. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    219
    I guess that's because Visual Scripting is meant to help beginners. It's easier for an experienced dev to uninstall a package, than for a beginner to install one. I think they should instead use the templates UI in the Unity Hub for that, though; they could have a default template with a big title that comes with packages like Visual Scripting.
     
    Luxxuor, TangerineDev and DragonCoder like this.
  7. havokentity

    havokentity

    Joined:
    Sep 25, 2017
    Posts:
    27
    That's interesting, I have a similar specced system but with 3700x but when I changed to NVME 7000mb/s drive I got the time down from 6 seconds odd to 3.5 seconds. Guess it's disk stuff?

    Will be getting a very specced out 7950x system in a week or so built, will test on that as well. Hopefully it takes 2 seconds this time but I highly doubt it'll go lower than 2 seconds. Unreal works really well and changes are instantaneous on even mid sized projects so I think it's definitely some architecture problem with Unity
     
    TangerineDev likes this.
  8. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    410
    upload_2022-11-11_23-15-9.png

    What ya doin' Unity? Can't be closed through task manager, it's completely non responsive.
     
  9. Personuo

    Personuo

    Joined:
    Mar 19, 2014
    Posts:
    112
  10. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    367
    Firstly, my apologize for not coming back more often to the forum. I completely understand your frustration, and even if that doesn't help, let me say that we are also deeply impacted/frustrated by this situation.

    Yes, it is our responsibility. A deadlock is not acceptable and our teams are receiving such bugs and trying to address them. But we need a reproducible bug. If you have reported it with reproducible steps, then we should be able to fix it (if you have a link to a specific issue, please post it and we will have a look)

    On the general performance decrease for 2020/2021, the reality is that we won't be able to fix these versions to the state it was before. What happened between 2018 and 2022 is that we have increased by x4 our C# codebase from 3M lines of code to 12M lines of code. This has a direct consequences to the Unity editor, as we are still using Mono which is very slow compared to .NET. We were also not tracking performance of the editor for all the packages/templates that we release, and so a regression could go unnoticed for months. We are still trying to address this specific problem by adding performance regressions to these. Also, in the meantime, the compilation pipeline has evolved 3 times and has introduced regressions that are unfortunately "unfixable" with the current rules of backporting that we have in place.

    As the team handling the entire Scripting part has been pretty stretched thin in terms of resources, it has become almost impossible to support all the LTS and work on the technical debt. Since the beginning of the year, despite many folks at Unity trying to fix things here and there, the return on investment is very low (e.g ~100-400ms while the current iteration time for a basic project is more around 4 to 6s) and so we are reaching a point where we need to tackle the structural problems (Moving away from Mono to use instead CoreCLR, moving away from the full domain reload....etc.).

    Everybody in the .NET group at Unity is deeply involved in trying to solve this but we are facing many internal constraints that are slowing or blocking us to solve this efficiently. I believe that we will be able to get back to a 1s iteration time, but it's not there yet.
     
  11. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    391
    Thank you for the update. It is greatly appreciated.
     
    Jes28 likes this.
  12. camirving

    camirving

    Joined:
    Jan 20, 2014
    Posts:
    91
    It is sad that the team is lacking resources. Such a core part of the engine should have more resources. Thanks for the update, though. I hope you guys get more resources to fix this.
     
    DrPoole, OCASM, Lahcene and 2 others like this.
  13. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    873
    Also apreciated.
    Well, in the meantime, everybody get powerful computers, I suppose.

    Deadlocks and generally rare multithreading-related bugs are the worst to debug. Big thanks for Burst to exist in Unity against that.

    That said, it somehow has to have something to do with the project, because by far not everybody experiences them. (I only vagualy have memories of having had to kill Unity during reload at some point and think that was while I was messing with a custom DLL).

    What I'd suggest for someone who is having that problem:
    Do bruteforce to ensure reproducability and then shrink down the project step by step until the problem disappears to figure the cause.

    By bruteforce I mean write a script outside Unity (python or something) that edits a file in the project to trigger a reload. Then let Unity write into some external file after the domain reload (there are some hooks available for that). That file is watched by the python script so it knows when recompile was successful. Then the python script does an edit again and so on until the reload time is over a threshold which means deadlock or crash occured.

    That may take a few hours of work to set up and possibly days to run (with reductions of the project between), but it may solve your problem.

    Edit: Using a file as interprocess communication to detect succesful reload could be omitted if you find some cache file which Unity modifies on each reload already. Commit the temp directory to a new repo without gitignore to find that out perhaps.
     
    Last edited: Nov 16, 2022
  14. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
  15. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    31
    TangerineDev likes this.
  16. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    Also they already have a working prototype of the Standalone Player/Build in CoreCLR which builds super duper fast!

    So I'll assume it won't really take that long, to release...
    If I had to guess, I would put my bets on 1.5 to 2 years of time until this releases in the latest alpha fully, so with the editor using CoreCLR.
    This is actually pretty hype XD
     
    Last edited: Nov 17, 2022
  17. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    662
    It was already mentioned that the standalone player gets a coreCLR option first. a coreCLR based editor later. I think the player version comes with either 2023.1 or 2023.2, editor with 2024.x, or 2025.x. Iteration times will only change with the editor version.
    It was also mentioned that the target is only changed to .NET 7+ with the editor version, until then with .NET Standard 2.1
     
    Last edited: Nov 17, 2022
    StellarVeil and TangerineDev like this.
  18. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    31
    Maaaaan in 2 years we'll be at like .NET 9 and C#... 12? I think. Long ways away.

    I have to admit it's pretty saddening to hear that the scripting team is so stretched in terms of resources. Joining up with .NET proper is kind of insanely big for the engine.
     
    Last edited: Nov 17, 2022
  19. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    410
    Ten hours, hilarious.

    upload_2022-11-17_10-43-50.png
     
  20. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    2,868
    theforgot3n1 and DragonCoder like this.
  21. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    873
  22. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    391
    You could kill the process and restart Unity. Not ideal for sure, but it beats waiting for several minutes (or hours).
     
  23. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    873
  24. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    367
    This has been flagged higher up in the past months and we are getting many positions opened to help the .NET group. Also more should come next year, so I'm optimistic that we will be able bring significant improvements to Unity to get the latest .NET (CoreCLR) and MSBuild improvements.
     
  25. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    Do you mean next year as in after December we'll hear some amazing news or next year as in November 2023?
     
    Last edited: Nov 17, 2022
    Trigve and Lahcene like this.
  26. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    410
    I just left it running to see if it was just lagging and ended up forgetting all about it - it's inpossible to kill it in task manager and when I manually restart it hangs on that like it's trying to kill it but can't so have to hard reset. I do wish I didn't have to deal with this and I need to back up pretty soon. :)

    I've uninstalled everything related to Unity, have reinstalled, but Unity can not complete because it hangs on a process rebuilding the libraries I removed, so I can't continue.

    I CAN NOT kill it - I have to do a hard reset.

    upload_2022-11-18_18-32-55.png

    upload_2022-11-18_21-53-45.png
     
    Last edited: Nov 18, 2022
  27. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    Unity?
    Can I get a response? Please!?
     
  28. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    304
  29. Igotlazy

    Igotlazy

    Joined:
    Jan 15, 2018
    Posts:
    31
    Oooo, what kind of time gains are you experiencing?
     
  30. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    367
    No amazing news. By "more should come next year", I meant more hiring.
     
  31. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    (o*。_。)o
    I'm sorry for misunderstanding...
     
  32. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    304
    Hard to tell, does seem a bit less 'hangy' if that's the word! I only have small projects so hard to test the improvements that affect larger projects.
     
  33. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    304
    Actually, there is 1 major change. As I use Burst a lot, I get the compile times in editor. These are down by a factor of 10-20x, which is interesting considering this is just linked to Burst.
     
  34. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    304
    These were previously all in at least 3 digits, up to almost 3 seconds.

    upload_2022-11-21_23-2-23.png
     
  35. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,290
    Thanks for the update and transparency!
    Fingers crossed that the higher-ups who manage and define the resource allocation realise the importance of working on core faster iteration times instead of any number of other random un-needed side features. :D Historically, Unity has often been chosen because of its faster iteration times. If that regresses then Unity loses a huge benefit and it becomes more attractive for the community for other engines with faster speeds (Godot and even UE5 are much faster right now).
     
    Trigve, Ghat-Smith, ontrigger and 5 others like this.
  36. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    Bro... At this point I would stop hoping that anything will improve anytime soon.

    It really is just an issue of Unity developing the technologies needed for CoreCLR to work.
    We will have to wait for that. In the mean time just use Godot for 2D, Unreal for 3D and Unity for Mobile 3D.

    Hopefully the wait will be max 2 years, but this is being optimistic...
     
    Last edited: Nov 25, 2022
    havokentity likes this.
  37. valarus

    valarus

    Joined:
    Apr 7, 2019
    Posts:
    399
    CoreCLR may be solution instead of Mono but please could you redesign, optimize and most importantly reduce C# codebase in half or more?
    Also high amount of data flow in HDRP API, Burst, packages and libraries inevitably slow down the editor responsiveness and worsen script compilation.

    I think reducing the API and codebase should also be part of the design plan.
     
    havokentity and TangerineDev like this.
  38. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    Definitely! Unity's whole API is kinda bloated, if for backwards-compatibility or simply them overcomplicating stuff, it is bloated!
     
  39. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    873
    And.. what code exactly should do that what is missing then?
    Sure there are some downsides of this as well, but all in all it was a good decision to take more stuff out of the black box which is the Cpp side of the engine. Thanks to packages being C# you can edit them! It's not extremely often that you need it but it enhances the engine to have that possibility.

    Whether the C# code could be improved? Possibly. No codebase is perfect. Thinknit's illusory to believe the code base could be halved while keeping the same functionality. People would scream if they drop significant backwards compatibility as that locks out people who have to update their project due to appstore or console requirements.
     
    bdovaz likes this.
  40. Andy-Touch

    Andy-Touch

    A Moon Shaped Bool Unity Legend

    Joined:
    May 5, 2014
    Posts:
    1,290
    Myself and millions of other people (and billions of consumers of games) currently rely on Unity being the best tool for the job because it is what we have invested our time into learning and building tooling around for our careers and income. Of course we are going to hope that things get better and improve. :)

    But ultimately there is a tipping point in terms of productivity; as the workflows and engine becomes more cumbersome, problematic and slower this adds extra unwanted debt. Studios (and any business) are run on how much things cost compared to the return it gives for the task; iteration time is one of these factors. Ive already shifted one game im working on from Unity to Godot purely because testing on device & building to mobile is light years ahead; its faster for me to rebuild my entire Godot game and deploy directly to device than it takes to enter playmode in the Unity editor. That time saving scales up significantly and if Unity doesn't address this sooner then it loses one of the biggest benefits it has sold itself on for the past 15 years (And why many studios shifted from other engines and tech to Unity in the first place; the shift can happen again from Unity to other tool and could argue thats already happening as projects are being sunset and new ones started).
     
    Last edited: Nov 25, 2022
  41. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    304
    Still think they should start again and make a Unity 6. The other engines seem to make new/breaking versions. Saying that, I didn't use the older versions, was say Unity 5 a breaking change from Unity 4, or is everything built even further back for seamless compatibility?
     
    StellarVeil likes this.
  42. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    410
    I'm using 2021.3.14f1 now, but at the same time I bought a new SSD for my unity projects as I thought mine may be faulty.
    I'm getting pre-2019 version iteration times, I have other SSD's - has everyone aligned their partitions? I don't know if it's related - I only had to 'realign' one, and that's the one my unity executible was on. It's been fine ever since.
     
  43. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39

    THE JOURNEY BEGINS!

    _________________________________________

    Here's the source if anyone wants to follow with me :p

    How to Check and Run SSD Alignment in Windows 10? (diskpart.com)


    _________________________________________

    So I first checked if it was already aligned... (see section
    SSD partition alignment check in two methods)
    1. I opened msinfo32
    2. I went to the disk and this is the result ( some of the specs are also there, but keep in mind this is a laptop so I'm limited to about 3000mb/s )
    3. So the value was 999,547,731,968 bytes!
    4. upload_2022-11-25_20-20-21.png
    5. Now the only thing left is to divide this with 4096 aannnnnd????
    6. I get a round number ( 244,030,208 to be precise )

    So my partition is aligned...

    _________________________________________

    The Test

    So the weird thing is Unity this time is somehow fast?

    The first time I changed a line of code it took about 9s.
    After that first "warm-up" modifying code was almost 3s-5s.

    I turned down the Idle Import Worker Shutdown Delay setting ( In Project Settings/Editor ) to 1s to make sure the cores were fully idle, but it was still fast...

    The Task Manager shows this...
    upload_2022-11-25_20-42-52.png

    DISCLAIMER: I DID QUIT EVERY BACKGROUND APPLICATION (e.g. Discord)

    upload_2022-11-25_20-44-28.png

    Also Unity itself is literally at 0% of the processes...

    Conclusion?
    So I guess they did something at Unity? Hooray!

    I wouldn't call it pre-2019 iteration times, but it's damn usable, while we wait for CoreCLR!

    _________________________________________

    This was my OWN experiment feel free to report your own experiences too!
     

    Attached Files:

    davidnibi likes this.
  44. havokentity

    havokentity

    Joined:
    Sep 25, 2017
    Posts:
    27
    Hmm doubt if much has changed because my disks are all aligned, always have been, always been using SSDs too.

    Unity 2021.3.14f1 takes about 3 s for a very large project (MRTK/Hololens 2 based) when I change a line of code.
    But even a new empty project with 1 script takes about 1.5 to 2 seconds to reload domain etc when I change a line of code. (Almost same time as giant project with
    atleast 100 classes)

    I think this is still really annoying, wish it would take < 0.1 s

    My times are always sub 3 seconds since always because this is with a very high end system with 7000mb read ssd, 7950x Overclocked, 64 gb ddr5 6000 cl30 RAM, 4090 all custom loop liquid cooled including the motherboard and ssds.(mobo/ssd also have a water block, so I guess it helps)

    Before the 7950x, I had a 3700x and over there too, it was < 3seconds for basic projects, big projects took around 7 to 10 seconds)
     
  45. TangerineDev

    TangerineDev

    Joined:
    Sep 28, 2020
    Posts:
    39
    No way you're complaining about 3 seconds XD

    Welp anyways as I said...
    We have to wait for Mono to be dead
     
  46. havokentity

    havokentity

    Joined:
    Sep 25, 2017
    Posts:
    27
    hahaha, xD I guess 3 seconds ain't THAT bad
     
    TangerineDev likes this.
  47. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    410
    I've honestly not noticed wait times since, I couldn't tell you the last time I thought 'why is this taking so long'.
    The only thing I did was change for a new hard drive where my project is based, and relalign my partitions on the drive my unity is installed (C:)