Search Unity

PropertyField extremely slow

Discussion in 'UI Toolkit' started by MartijnGG, Sep 8, 2020.

  1. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    I've been writing some custom UI for a ScriptableObject with an array.
    I create a `PropertyField` for every element in the array, and noticed that around 20 elements, Unity is taking over 25ms on `Bindings.Update` every few frames after the UI has been created.

    Once I hit about 40 elements, the UI becomes totally unresponsive.

    A quick profile shows that almost all time is spend in `SerializedProperty.get_isValid()`
    The image below is at 30 elements.

    upload_2020-9-8_12-48-39.png

    Does anyone have a suggestion on how to remove/reduce this insane overhead?
     
    Ghat-Smith and jamiebrynes like this.
  2. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    Can you append your custom UI script for reference?
     
  3. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    No problem

    The attached file contains the editor

    The ScriptableObject itself looks like this:
    Code (CSharp):
    1. public class EntityRepresentationMapping : ScriptableObject
    2. {
    3.     [SerializeReference]
    4.     public List<IEntityRepresentationResolver> EntityRepresentationResolvers
    5.         = new List<IEntityRepresentationResolver>();
    6. }
     

    Attached Files:

  4. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    One pitfall of the current api implementation is that BindProperty() will involve serializing the entire object every frame. This can be avoided by simply calling Bind() at the root level of your hierarchy and bind everything at once. This usage is fixed in one of our development branch and should ship soon. I modified your implementation a bit, let me know if that improves the situation.
     

    Attached Files:

  5. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    74
    Thank you very much for taking the time to look at the issue!

    Sadly it seems the fix has little impact. An array with 30 elements still takes between 20 and 30ms during `Bindings.Update` every few (7?) frames.

    Will this fix be applied only to the 2020.2 beta, or also a 2020.1 patch?
     
    Mehrdad995 likes this.
  6. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    398
    The fix will be available in the package version of UIToolkit, available for 2020.2 and 2020.1. Can you report the issue using Help -> Report a Bug ... ? That will help us getting the fix backported to the built-in editor versions.
     
  7. cjacobwade

    cjacobwade

    Joined:
    Jun 8, 2013
    Posts:
    10
    Hi folks, I'm running into the same serializedObject updating every frame slowdown issue here. I've used the same pattern you explain here of having the highest parent possible Bind once but agree with MartijnGG that forcing large lists to rebuild whenever changed isn't really workable.

    What's the status on this fix going into the UIToolkit package for 2020.1?
     
    Mehrdad995 and watsonsong like this.