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

ScriptedImporter Inspector becomes extremely slow with large text files

Discussion in 'Experimental Scripting Previews' started by GeorgeAdamon, Nov 5, 2019.

  1. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
    Hello everyone,
    I have created a custom Scripted Importer which parses a .csv file and generates a ScriptableObject main asset & a mesh sub-asset, along with a ScriptedImporterEditor which handles the UI.

    I have noticed that when the .csv files tend to be large (200.000+ lines / 20+MB), any UI operation while the .asset is selected lags considerably. Selecting the .asset in the first place on the Project window, changing some settings on the Inspector, pretty much any mouse operation regarding that object, makes UnityEditor horribly slow.

    Keep in mind, the OnAssetImport() function call itself is fast, and even removing all the functionality from it doesn't solve the issue. The issue persists even if I disable my Editor script.

    Even if I completely remove my Importer, the text asset selection is still slow, which leads me to believe that Unity does some pre-serialization any time the .asset is selected.

    Any help would be much appreciated!
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    You could try to turn on editor profiling and deep profiling in the profiler to see what's going on.
     
  3. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
    Aah yes, of course. I attach the results below.
    UnityEditor::ActiveEditorTracker.VerifyModifiedMonoBehaviours 

    called from
    UnityEditor::InspectorWindow.OnInspectorUpdate
    takes up 712ms (94%)!
    I also noticed that there's a big GC spike whenever I select the asset.
     

    Attached Files:

  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    Hmmm, it might be that the inspector's checking to see if the asset's been modified? Seems strange.

    What Unity version are you on? Could you enable/disable asset database v2 and check if that makes a difference?
     
  5. GeorgeAdamon

    GeorgeAdamon

    Joined:
    May 31, 2017
    Posts:
    48
    Thanks for the suggestion Baste. I'm using 2019.3.b10. Switching to the Asset Database v1 made no difference unfortunately.
     
  6. EmilieCollard191

    EmilieCollard191

    Joined:
    May 8, 2019
    Posts:
    77
    Hello did you fix the problem? Or did unity fix it? I have the same problem on version 2019.4.28
     
  7. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    I have the same issue with Dialogue Database of "Dialogue System for Unity" asset.
    Basically one 20mb serialized asset. Whenever this asset is selected in Project view Unity becomes extremely laggy. Profiler shows similar picture.
     
  8. shma_unity

    shma_unity

    Joined:
    Jun 13, 2018
    Posts:
    118
    I just had a similar problem happen and found out what caused it for me. (same profiler results)

    I had a custom Editor to draw in the inspector. The monobehavior itself had simple several serializable objects (not even unity objects) to hold data. Those objects had references to their parent object (with the monobehavior at the top).

    Because I would copy lists of serializable object between monobehaviors I would have to update the parent references accordingly. I would just do an assignment of the parent object in the OnInspectorGUI().

    From what I can tell, this has caused the slow down, as unity possibly marked that down as the serializable object being changed causing the whole serialization to check and verify for changes.

    Adding a check first to see if the parent object is actually different fixed the slow down.

    TLDR: Be careful with assigning serialized objects every update in the editor loops.
     
  9. Black_six

    Black_six

    Joined:
    Dec 8, 2020
    Posts:
    11
    I'm in the same situation as you. It's now 24MB. Have you solved this problem?Thanks!
     
  10. Black_six

    Black_six

    Joined:
    Dec 8, 2020
    Posts:
    11
    Hello, I'm not sure what you mean by "Adding a check first to see if the parent object is actually different fixed the slow down." Could you please let me take a look at this part of the code? Thanks!
     
  11. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    If the asset has a custom editor, you could mark chunks of that editor with Profiler.BeginSample and Profiler.EndSample, to see which part is being slow.
     
  12. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    I tried to reimplement the custom inspector so it did returned right at the beginning of OnGUI and it's not helped a bit. The issue is on the engine side :confused:
     
  13. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    Yep, we solved this by splitting our Dialogue Database to bunch of smaller assets, combining them in playmode. I found no better way to fix it
     
  14. Black_six

    Black_six

    Joined:
    Dec 8, 2020
    Posts:
    11
    I got a similar reply from the developer of the dialogue system. At present, the only way is to split the database.