Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

PropertyField extremely slow

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

  1. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    73
    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:
    262
    Can you append your custom UI script for reference?
     
  3. MartijnGG

    MartijnGG

    Joined:
    May 3, 2018
    Posts:
    73
    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:
    262
    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:
    73
    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?
     
  6. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    262
    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:
    9
    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?
     
unityunity