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. Dismiss Notice

Drastically slower Visual Studio Code IntelliSense in Entities 0.50

Discussion in 'Entity Component System' started by Abbrew, Mar 19, 2022.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Code completion, error actions, error highlighting - all of these have slowed down to a crawl after Entities 0.50. This may have to do with all the injected post-processor code (the one that requires making all System classes partial). Is there a fix for this?
     
    goncalo-vasconcelos likes this.
  2. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Last edited: Mar 19, 2022
  3. JohnnyTurbo

    JohnnyTurbo

    Joined:
    May 17, 2017
    Posts:
    36
    DreamersINC likes this.
  4. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    That's unfortunate... Maybe I have to switch IDE :(. If anyone comes across a fix for VS code please let me know.

    You are using rider right? Is everything working fine there? Or do you also get suggestions of the generated methods and so on when you type "this." in a systembase?
     
  5. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
  6. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Actually, this did not fix the problem. My Visual Studio Code keeps slowing down after several minutes of use, then speeding back up to normal. I have yet to locate what's causing this. I've tried making my Mono installation match the 2.0 NET Standard version, which is the one that supports source generation, but it's not working
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    I've had no issue with rider
     
    xVergilx, Anthiese and desertGhost_ like this.
  8. JohnnyTurbo

    JohnnyTurbo

    Joined:
    May 17, 2017
    Posts:
    36
    Yes, I am using Rider. Haven't noticed anything out of the ordinary when typing "this." in a SystemBase. What does it come up with for you?
     
  9. AlexHolderDev

    AlexHolderDev

    Joined:
    Jul 2, 2014
    Posts:
    35
    This is going to come up a lot since Unity Hub still includes Visual Studio 2019 as the IDE, rather than Visual Studio 2022. Fun times ahead.
     
  10. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    For what it is worth I still use VS19 because I have custom tools for it and haven't taken the time to migrate to a better IDE like Rider. I have not noticed a difference in workflow or performance with source generators yet. With that said, I don't do breakpoint debugging unless I absolutely have to, and I haven't reached that threshold yet with DOTS 0.50.
     
  11. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    You can see in this post: https://forum.unity.com/threads/how...-scanning-temp-generatedcode-in-0-50.1254726/
    But I can explain it here too. For example, lets say I have a method in this systembase called "CastSpell". When I type "this.castspell" I also get a suggestion for the generated method "__CastSpell_291F8998".

    c339339e2a8c02ffd78575918f8e8acd.png

    I can also see a lot of other internal stuff like the queries and job execute methods:

    aaaf3208ee06fb50dc75f5aa679dd063.png
     
  12. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    It seems like the slowness is only present when working in assemblies that both references Unity.Entities and has lots of code-gen linked to it.

    I have some utility assemblies that references Unity.Entities but has very little code-gen. When I'm working there everything is fast but as soon as I switch to the main assembly with lots of systems everything becomes slow again. If you have a similar situation maybe that's why you are experiencing these ups and downs in performance.

    Also I noticed that by removing Unity.Entities reference from main assembly, everything is fast there as well.
     
    Last edited: Mar 21, 2022
  13. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    909
    How does support for Code Generation even look?
    I'm using VS2022.
     
  14. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    I'm also wondering that
     
  15. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    I think I found a solution to the slowness.

    Go into all .csproj files and remove the ItemGroup where it says:
    Then restart omnisharp or VS code.
    It should be fast as before 0.50 again.

    Each time you want to open the project, don't use Assets -> Open C# Project as that will regenerate the Analyzer includes. Instead just open the project folder with your file explorer.

    I'm not sure what features are lost when excluding the analyzers but so far I haven't noticed anything besides being able to quickly jump to the generated code by ctrl+clicking on the class name that is implementing systembase. But of course you can still manually go to Temp/GeneratedCode and take a look.

    If you have lots of .csproj files, you can use this regex search pattern:
    and replace it with nothing.
    For safety, include only .csproj files.
     
  16. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Looks like we tentatively have a fix for this coming in a patch release. It caused a bunch of pain for internal devs too.
     
  17. vildauget

    vildauget

    Joined:
    Mar 10, 2014
    Posts:
    120
    Thank you @CookieStealer2 . Much appreciated.

    So now I know that
    Code (CSharp):
    1. ctlr-shift-h
    can do replace in all files for open folder - wow, that's powerful.
     
  18. Richay

    Richay

    Joined:
    Aug 5, 2013
    Posts:
    75
    This is still occurring for me, Entities 0.50.1-preview.2, Visual Studio 2022 17.3.0 preview 1.1. Two separate ECS projects have ridiculously slow intellisense, but standard Unity projects run as normal.
     
    CookieStealer2 likes this.
  19. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Yes, I still have to remove the analyser includes to get full speed. After the patch it is better but still not fixed.
     
    Richay likes this.
  20. Richay

    Richay

    Joined:
    Aug 5, 2013
    Posts:
    75
    Can confirm that deleting all of the analyser rules completely fixes intellisense. Thanks @CookieStealer2!
     
  21. fcorbel

    fcorbel

    Joined:
    Oct 27, 2016
    Posts:
    7
  22. CameronPenner

    CameronPenner

    Joined:
    Mar 7, 2015
    Posts:
    6
    I have deleted the analyser rules, and VSCode runs great. But the csproj files keep getting updated, and the analyser rules just come back and break everything. I went to Preferences -> External Tools -> Generate .csproj files for: and unchecked everything, but it's still just reverting back.

    Is there a more permanant solution?
     
  23. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    I too got tired of manually running the regex over and over again. Luckily I found out that there is a certain callback (OnGeneratedCSProject()) in the AssetPostProcessor class that we can hook into when the .csproj files are generated. So I've made this script that automatically removes the analyzers each time a .csproj file is generated. It also adds a button in the editor to toggle it on/off. Feel free to use it.

    Code (CSharp):
    1. #undef DEBUG
    2.  
    3. using UnityEditor;
    4. using System.Linq;
    5. using System.Xml.Linq;
    6.  
    7. public class AnalyzerRemover : AssetPostprocessor
    8. {
    9.     private const string menuPath = "Custom/Remove analyzers from .csproj files";
    10.     private const string editorPrefsKey = "AnalyzerRemover.isEnabled";
    11.  
    12.     public static bool isEnabled
    13.     {
    14.         get => EditorPrefs.GetBool(editorPrefsKey, defaultValue: true);
    15.         set => EditorPrefs.SetBool(editorPrefsKey, value);
    16.     }
    17.  
    18.     [MenuItem(menuPath)]
    19.     private static void OnMenuButtonPressed()
    20.     {
    21.         isEnabled = !isEnabled;
    22.     }
    23.  
    24.     [MenuItem(menuPath, isValidateFunction: true)]
    25.     private static bool ValidateMenuButton()
    26.     {
    27.         Menu.SetChecked(menuPath, isEnabled);
    28.         return true;
    29.     }
    30.  
    31.     private static string OnGeneratedCSProject(string path, string contents)
    32.     {
    33.         if (!isEnabled) return contents;
    34.  
    35.         var csprojXML = XDocument.Parse(contents);
    36.         var ns = csprojXML.Root.Name.Namespace;
    37.         var analyzers = csprojXML
    38.             .Descendants(ns + "Analyzer")
    39.             .Where(a => a.Attribute("Include")?.Value.Contains("SourceGenerators") ?? false)
    40.             .ToList();
    41.  
    42.         if (analyzers.Count == 0) return contents;
    43.  
    44.         analyzers.Remove();
    45. #if DEBUG
    46.         UnityEngine.Debug.Log($"Removed analyzers from: {path}");
    47. #endif
    48.         return csprojXML.ToString();
    49.     }
    50. }
     
  24. CameronPenner

    CameronPenner

    Joined:
    Mar 7, 2015
    Posts:
    6
    That script works perfectly! Thank you so much!
     
    jiexiangshen likes this.