Search Unity

Bug Displaying large script file in Inspector window causes CPU spike

Discussion in 'Editor & General Support' started by JWerner, Apr 22, 2023.

  1. JWerner

    JWerner

    Joined:
    Dec 18, 2016
    Posts:
    8
    Using Unity 2021.3.23f and 2021.3.16f, Windows 10

    Previewing a large script file in the Inspector window causes CPU usage to spike. The threshold seems to be ~1000 lines in the file. The CPU usage stays high until the file is no longer being displayed in Inspector. Double clicking a file to open in VS will leave the editor churning away in the background until some other file/object is selected. The attached screenshots show the difference in CPU usage that previewing a file causes.

    UnityEditor-NoScriptSelected.png UnityEditor-ScriptSelected.png
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,861
    This is probably expected behaviour, honestly. Serialised data viewed in the inspector is being serialised and deserialised every repaint. The same behaviour happens when viewing very large asset files, particularly scriptable objects that had been loaded to the gills with data.

    Not surprising that particularly large script assets (which are just text files, really) take a lot of overhead, particularly with IMGUI based drawers. Which I imagine means the script asset inspector is still using IMGUI and hasn't been updated to UI elements.

    FWIW, you should use the profiler to pinpoint where the overhead actually lies, rather than guessing with task manager.