Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Performance spike on Canvas.SendWillRenderCanvases when moving a panel

Discussion in 'UGUI & TextMesh Pro' started by CremaGames, Dec 1, 2014.

  1. CremaGames

    CremaGames

    Joined:
    Mar 5, 2014
    Posts:
    59
    Hi,

    I'm having performance problems moving a panel in my UI. I'm moving the panel with a Coroutine that updates the anchoredPosition. The panel has a lot of childrens (a scrollable object with some groups inside, some images, texts...).

    Here's the editor picture when calling the coroutine:



    As you can notice, the spike on SendWillRenderCanvases is very noticeable, and this is on a computer, in the mobile is even worse.

    Is there anything I can do to improve this performance?
     
  2. CremaGames

    CremaGames

    Joined:
    Mar 5, 2014
    Posts:
    59
    The same thing happens in the patch1.
     
  3. hubecube_

    hubecube_

    Joined:
    Aug 26, 2012
    Posts:
    18
    Same here - I am searching around for a solution... I suspect that the UI system uses the physics system and raycasting so just like moving colliders in games causes lag, moving or activating ui elements causes lag

    You can avoid enable/disable by using multiple canvases and changing the gameobject.layer to one that is not rendered by the camera. This saves draw calls without lag assocaited with SetActive(false)

    I am still trying to figure out a solution for moving the elements without performance spikes, testing out an approach where I move the camera so that elements stay in place.
     
  4. tstpierre_nss

    tstpierre_nss

    Joined:
    Jul 3, 2012
    Posts:
    118
    Interesting tip. Switching to a culled layer. I just spent the evening troubleshooting this as well. This is my last spike I'm leveling out on the profiler
     
  5. IvovdMarel

    IvovdMarel

    Joined:
    Jun 1, 2014
    Posts:
    9
    I managed to get a huge performance boost (from 5 FPS to 50) by using the following code:

    boolshouldShow = Mathf.Abs(scrollRect.InverseTransformPoint(t.position).y) < scrollRect.rect.height;
    if (shouldShow != childTransform.gameObject.activeSelf)
    {
    childTransform.gameObject.SetActive(shouldShow);
    }

    I had to refer to a childTransform which contained all the RectTransform-children, because if I would deactivate the item itself, my VerticalLayoutGroup would start messing up order etc.

    This is only useful for really large scrollviews with many items that contain many sub-items.

    Changing the layer to a layer that wasn't rendered didn't change much in performance for me.
     
  6. tstpierre_nss

    tstpierre_nss

    Joined:
    Jul 3, 2012
    Posts:
    118
    I did something to the same effect. Layering wasn't helping perf. had to disable/enable.
     
  7. cntoplolicon

    cntoplolicon

    Joined:
    Sep 28, 2014
    Posts:
    1
    Same problem encountered here. Got a huge perf boost by removing an UI image that tiles across the whole screen. Please check whether there's any tiled UI images in your scene. The existence of them seem to cause performance spike, even if they are not the children of the element you're moving. Disabling them doesn't seem to help. Had to remove.
     
    MikeCurrington likes this.
  8. MikeCurrington

    MikeCurrington

    Joined:
    Feb 13, 2013
    Posts:
    2
    The tiled UI image tip was great, thanks.
    A 8x8 square Image set to tile the whole screen was causing SendWillRenderCanvases to take 20ms for me, disabling the image took it down to 2ms. I'm not quite sure how big a mesh the canvas was generating to do all those tiny tiles, but I'm assuming it was huge and that it is generated every frame. Easy fix, difficult to find.
     
  9. IvovdMarel

    IvovdMarel

    Joined:
    Jun 1, 2014
    Posts:
    9
    A bit late, but another thing I found out was that my Canvas was set to PixelPerfect. Disabling this tripled my performance (simple bool check).
     
  10. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    had the same problem, and wanted to try you option, but cant understand, how do you hide elements in VerticalLayoutGroup in new GUI and still got container size with child object not minimized?
     
    adreyer likes this.
  11. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    604
    That helped a lot!

     
  12. jm91086

    jm91086

    Joined:
    Nov 17, 2014
    Posts:
    1
    Add a Layout Element component to the elements with a minimum/preferred height/width (depending on which is relevant). When you disable the child objects of the Layout Element object, then the parent object will maintain the height based on the Layout Element properties.
     
  13. Derek-Wong

    Derek-Wong

    Joined:
    Jan 5, 2015
    Posts:
    16
    You SAVE MY LIFE MAN!!!!!!
    untick the pixel perfect make my performance BOOST like ....6 times? from 33 fps to 200 fps something =-=

    With Pixel Perfect 螢幕快照 2015-06-07 上午2.37.55.png

    untick Pixel Perfect
    螢幕快照 2015-06-07 上午2.38.14.png
     
  14. TruffelsAndOranges

    TruffelsAndOranges

    Joined:
    Nov 9, 2014
    Posts:
    92
    Anyone found a solution to this one? I only have a single "UI.Text" and keep getting this performance spike. :S
     
  15. Tethys

    Tethys

    Joined:
    Jul 2, 2012
    Posts:
    672
    Thanks for the tips guys! Unticking Pixel Perfect now frees up the lag I had in the scene where I pick up my UI. ;)
     
  16. JamieFristrom

    JamieFristrom

    Joined:
    Nov 2, 2012
    Posts:
    20
    For me it was the Outline script - giving up on that gave me huge gains.
     
    path14 likes this.
  17. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    I had a major performance issue with SendWillRenderCanvases showing up at the top of the profiler. Disabling the "pixel perfect" option on the canvas fixed it. However, now I don't have pixel perfect rendering.

    Should this be considered a bug?
     
  18. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I have a similar issue, performance remains quite stable except for some spikes. In my case SendWillRenderCanvases appears at the top of list on all frames, in some rare cases it appears in second place just after Cfx.WaitForPresent. The spikes occur when apparently SendWillRenderCanvases calls GC.Collect. My UI is composed by only 5 sprites and 1 text, and I am not using "pixel perfect"... the spikes occur even when the UI remains unchanged. profiler.png
     
  19. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    This seems to be a Unity 5.2 bug, I tested with Unity 5.1.3 and as you can see performance is more stable and the spikes are caused in this case by Gfx.WaitForPresent, no garbage collection issues at all.

    profiler513.png

    Same game, same assets, everything the same, just downgraded to 5.1.3.

    The Android build has a notorious difference between 5.1.3 and 5.2, the game built with 5.1.3 performs smoothly, responds instantly and looks perfect, while the 5.2 build freezes often and due to that is extremely hard to control, not to mention the background becomes corrupted after playing a while.
     
    NotaNaN, nirvanajie, Ghikya and 2 others like this.
  20. clearrose

    clearrose

    Joined:
    Oct 24, 2012
    Posts:
    349
    Hello, we got the same bug as Georgeq.

     
  21. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    Last edited: Sep 24, 2015
  22. victorfisac

    victorfisac

    Joined:
    May 7, 2015
    Posts:
    1
    In my case, I tried by disabling pixel perfect but sometimes SendWillRenderCanvas fill about 70-90% yet. I solved it by switching my font from dynamic to static (I have so much UI Text with same dynamic font but different sizes and animated fontsize with code in some texts).

    Now with a static fontsprite the SendWilLRenderCanvas fills just 3%. I suppose the spritefont texture was being recalculated each frame.
     
    MGGDev, nirvanajie and IgorAherne like this.
  23. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    MrEsquire likes this.
  24. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    Update:

    Upgraded to the latest patch 5.2.1p2, and I thought I saw some improvement at first, but as you play the game longer it gets worse and worse...

    For now I had to downgrade back to 5.1.1 and the problem no longer occurs. I hope they fix it in a coming patch.
     
    wlwl2 likes this.
  25. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    5.2.1p3 is out now, I wonder if it helps?
     
  26. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    Hmm, I don't see anything related to this in the release notes, but will give it a try.
     
  27. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I'd like to turn pixel perfect off, but it makes my text look terrible. How do you make text look good without it?
     
  28. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    We're seeing 70ms spikes in Canvas.SendWillRenderCanvases in PC standalone builds made with 5.2.1p3 and 35ms spikes with 5.1.1f1. Any pixel perfect canvases are disabled in this case.

    Can someone shed some light on what asset issues can cause these spikes? Is this a "too many drawcalls" situation, or something entirely different? What does this Canvas method do?
     
    Last edited: Oct 12, 2015
  29. pltremblay

    pltremblay

    Joined:
    Aug 24, 2014
    Posts:
    34
    I got the same issue, Unity 5.2.1f1. I disabled my UI elements one by one until I finally isolated what seems to be the source.

    I have a Quick Slot menu displayed in the bottom of my screen (similar to weapon, spell and item quick use in Dark Souls) and my Text elements have a Shadow Script attached to them. Just by disabling those, the GC Collect spikes vanished with them.

    EDIT: I investigated a bit more and found that I was changing the alpha of my text element through code, and that I was passing a NaN value. I fix the issue so it always assign a correct number and that removed the spikes too. So it was not directly the Shadow script that was causing this.
     
    Last edited: Oct 19, 2015
  30. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    I got same issue, Unity 5.2.1p4 (Windows Editor and iOS builds).
    I'm using UI mask. After I disable them spikes disappear, but it's not an appropriate solution for me (
     
  31. pltremblay

    pltremblay

    Joined:
    Aug 24, 2014
    Posts:
    34
    What is inside your mask? And how many elements? I have UI Mask as well, around 100+ buttons in it (it is a list view) and it does not take too much processing.
     
  32. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    I have one Tiled Image inside mask. Size of image bigger than mask area - in this case I can change image position continuously, and it looks like it scrolls down endlessly, but in real after a small scroll down image "jumps back" on size of pattern, and user doesn't see this.
     
  33. pltremblay

    pltremblay

    Joined:
    Aug 24, 2014
    Posts:
    34
    I have somewhat the same too. I made a "compass" à la Skyrim. 4 images, North South East West and they scroll. When one is too far, let say to the left, I move it back to the right. But I does not have performance issue for that specific feature.

    According to this post, the bigger the image, the more likely it is to have the performance issue. What's the size of your image?
     
  34. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    Image size is 32x32 pixels, masked area is 1024x312 (and it fits device width), tiled image is 896x1122.
    So yeah, I can't say it small, but in 5.1 it was giving a smooth result.
    Also I change alpha via Color property. Interesting, changing of image Color could affect performance? I mean, does UI shader use Color parameter in any case, or only if it is different from default value...
    Also, maybe it's better to use simple bigger image with all pattern instead of using tile algorithm?
     
  35. pltremblay

    pltremblay

    Joined:
    Aug 24, 2014
    Posts:
    34
    When you change the alpha by Color property, you are doing something like this right?
    Code (csharp):
    1. Color tempColor = myImage.color;
    2. tempColor.a = targetAlpha;
    3. myImage.color = tempColor;
    I dunno if Color trigger the GC Collect. I personally have made a extension method for Graphics that uses a static Color property. This make changing alpha (or color) of a Graphic component much more elegant. And this avoid me to declare a tempColor every time.
     
    MGGDev and MESSI007 like this.
  36. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    No, I mean, I change it from his default value in Editor (I don't change it in runtime). In this case I can do this in Photoshop. But, I don't think this has any matter - UI shader must use it in anyway - changed or default it's used in calculation, I guess.
     
  37. pltremblay

    pltremblay

    Joined:
    Aug 24, 2014
    Posts:
    34
    Well, in that case it would surprise me that using a different color could cause the problem.
     
  38. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    470
    If you're seeing these spikes, can you share some info on what type of canvas you're using? (screen space overlay, camera, world space) and what type of movement is triggering it?

    Our worst case right now is with a screen space overlay canvas and changing the sibling order of the UI elements below it to resort. In 5.2.2p1 we get 60+ms spikes in Canvas.SendWillRenderCanvases. The elements do contain masks, unfortunately.
     
    Last edited: Oct 28, 2015
  39. ChiuanWei

    ChiuanWei

    Joined:
    Jan 29, 2012
    Posts:
    131
    thanks man!!!! YOU SAVE ME !!!!
     
  40. Lost2048

    Lost2048

    Joined:
    Aug 26, 2015
    Posts:
    1
    Thanks man.You save a game 0 0、
     
  41. GarretPolk

    GarretPolk

    Joined:
    May 26, 2013
    Posts:
    49
    Thanks for the answer! I have the same problem on 5.2.3f1. I have a countdown timer showing milliseconds with a outline script. Each frame was allocating 77.4KB and I was getting stuttering every few seconds when a garbage collection event happened.

    Has anyone checked these issues on 5.3 ?
     
  42. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    I completely skipped 5.2.X because of this issue, but now I upgraded to 5.3 and there don't seem to be any performance hits related to this any more.
     
  43. GarretPolk

    GarretPolk

    Joined:
    May 26, 2013
    Posts:
    49
    Thanks Tomer. 5.2.x had a ton of UI bugs so I've been hesitant to move to 5.3 in case it got worse.
     
  44. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
  45. Chintao

    Chintao

    Joined:
    Jun 26, 2014
    Posts:
    54
    <3 thank you!
     
  46. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    I LOVE YOU
     
  47. Saulius

    Saulius

    Joined:
    Aug 10, 2010
    Posts:
    21
    With Pixel perfect enabled app frame rate drops dramatically when I scroll down. Also scrollrect contains some text and 1 image. I need Pixel Perfect enabled, because in UI I have 1px size lines (Image component), without Pixel Perfect on these lines flicker. I need to deliver app to client, but I can't with this problem. Could anyone help me with this?

     
  48. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    i'm not familiar with unityUI, but im wondering, can you Disable Pixel Perfect on Start of Dragging, and on End of Dragging, Enable it again?
     
    Energy0124 likes this.
  49. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    118
    I have similar spikes and tried a lot of thigs. My solution was in canvas scaler settings. I had "Scale with secreen size" and match to height. Match to width solved it.
     
  50. Paul-Chen

    Paul-Chen

    Joined:
    Feb 25, 2016
    Posts:
    6
    Have you tried "Scale with screen size" and "Expand" on iPad?