Search Unity

Extreme slowdown traced to SerializedObject.ApplyModifiedProperties

Discussion in 'Prefabs' started by hippocoder, Feb 11, 2020.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi,

    According to profiler any changes made in editor and not in prefab stage cause a delay of over a second, pointing to SerializedObject.ApplyModifiedProperties.

    It doesn't occur if I unpack the prefab. Any ideas how to solve this? Why is it trying to even serialize?

    Unity 2020.1 a22, so it is recent.
     
  2. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Can confirm this on my end.
    Makes Odin Inspector unbearable to use on non-trivial prefabs right now.

    On a non-prefab, making changes takes 3-4ms, while on a prefab it jumps to 20-30.
    Even if I apply all overrides so that the only remaining override is the change I'm currently doing, it gets like that.
    The more changes I do, the slower it gets.

    I reduced my prefab usage to the bare minimum already, but it still affects us.
     
    hippocoder likes this.
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I can't reproduce that here (tested with a Prefab with 1600 cube children on a fairly old laptop - it's smooth). Hard to know if your Prefab is orders of magnitudes larger, or if there's some other critical difference. Can you file a bug report with a project and repro steps that reproduces the issue so we can look into it?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It may be related to having an Array that's serialized but quite big. I have a byte array that's 30,000 elements big but it's a public field. The public field is hidden [HideInInspector] and very infrequently (usually never) modified.

    The depth of the object is not really an issue, it's just a skinned mesh with a typical hierarchy, no biggie in that respect, in fact not deep at all.

    As for case number I don't have time right now, I'll try this weekend, have deadline. Hopefully someone else can file or you can test with ODIN.
     
  5. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    My tests are with a list of strings.
    With a list of about 3000 elements, the slowdown is very visible in a prefab instance.

    To cause the slowdown, I just need to hold a key to constantly change an element in the list.


    If I do that with a non-prefab object, it's super fast even with MUCH larger lists.
    But with prefabs, it's very slow even on that smallish one.
     
    hippocoder likes this.
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I noticed a lot of strange behaviour with tools that build meshes or alter meshes/materials in the scene as well. It's as if the public inspector (not dedicated stage) - the legacy prefab behaviour is somehow bugged and serialising or doing heavy operations as well when it really shouldn't.

    Just a guess but it seems like when Unity added legacy prefab style editing in inspector, these problems flared up.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That reminds me, also it only gets bad if I ctrl+D duplicate the prefab in the scene and then mess with the component. It's probably related to that since I can only fix it by replacing the component or unpacking the prefab.
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It sounds like there are a lot more specifics in order to be able to reproduce than what was originally reported. We can look into this once we have a bug report. Also, if the issue can only be observed when using ODIN, then it's something to take up with the developer of ODIN. We'll need a bug report that reproduces the issue without using that.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah sadly I have no time so I've worked around it by avoiding prefabs for this, hopefully someone else will care to file seems like a common issue from people I've spoken to.
     
  10. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Same here, too pressed for time.

    One thing is for sure: it's not an Odin specific issue. I just happened to notice it while working on a large test list for a tool I had just created.


    If no one provides a # case here in the coming weeks, I'll try and create a repro for it.
     
  11. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Yep, this happens with 2021.3.11f1 too;
    Basically:
    - If prefab is inside a scene;
    - Modified via inspector;
    - Has large data structure list, or anything large that is required to be serialized;
    - Editor slows down to a crawl.

    Unpacking helps in this case.

    Another workaround is to separate data from the inspector user is modifying.
    E.g. move that large chunk of data to the separate component so that inspector won't call re-serialization.
    Hacky, but works as well.