If an element in the Xaml is set to isVisible="False" will it still have an impact on performance?

Hi All,

What I mean is that if you had lets say 600 elements in a XAML file for Xamarin forms and 599 of them were invisible, would this have an impact on performance and can anyone give specifics as to why? It would be really useful to know if items that are not visible still use processing power etc.

J

Best Answers

  • JamesMallonJamesMallon US ✭✭
    Accepted Answer

    @ManojkumarMali

    After some thought, your answer did not seem right, just because I couldn't imagine any developer writing a program like that. So I did my own research and opened up the Xamarin Forms source code.

    Here is what I found by looking at the StackLayout source:

    • If the item has IsVisible set to false it will still load the object into memory and make an iteration round a loop.
    • If the item has IsVisible set to false however, it will skip the calculations needed to render the object correctly.

    Here is a link to a small example of what I mean for anyone wondering in the future:
    https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/StackLayout.cs#L62

    So in conclusion, yes when there are items in your Xaml that are invisible some processing power will be used. But not nearly as much as it would if it was rendering an item that was visible.

Answers

  • ManojkumarMaliManojkumarMali USMember ✭✭✭

    Hi,

    Yes, the invisible elements also impact on your performance.
    All elements that you add on your xaml are compiled and load on target except commented elements.
    IsVisible property is just a part of UI effect.

  • JamesMallonJamesMallon USMember ✭✭

    Thanks for your answer @ManojkumarMali .

    I was wondering if you could tell me, if at run-time when the graphics elements are rendering, will things like HorziontalOptions and other attributes be processed and computed if the element is Invisible?

  • JamesMallonJamesMallon USMember ✭✭
    Accepted Answer

    @ManojkumarMali

    After some thought, your answer did not seem right, just because I couldn't imagine any developer writing a program like that. So I did my own research and opened up the Xamarin Forms source code.

    Here is what I found by looking at the StackLayout source:

    • If the item has IsVisible set to false it will still load the object into memory and make an iteration round a loop.
    • If the item has IsVisible set to false however, it will skip the calculations needed to render the object correctly.

    Here is a link to a small example of what I mean for anyone wondering in the future:
    https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/StackLayout.cs#L62

    So in conclusion, yes when there are items in your Xaml that are invisible some processing power will be used. But not nearly as much as it would if it was rendering an item that was visible.

  • IRONicMANIRONicMAN Member ✭✭

    @JamesMallon said:
    @ManojkumarMali

    After some thought, your answer did not seem right, just because I couldn't imagine any developer writing a program like that. So I did my own research and opened up the Xamarin Forms source code.

    Here is what I found by looking at the StackLayout source:

    • If the item has IsVisible set to false it will still load the object into memory and make an iteration round a loop.
    • If the item has IsVisible set to false however, it will skip the calculations needed to render the object correctly.

    Here is a link to a small example of what I mean for anyone wondering in the future:
    https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/StackLayout.cs#L62

    So in conclusion, yes when there are items in your Xaml that are invisible some processing power will be used. But not nearly as much as it would if it was rendering an item that was visible.

    What about elements and controls nested inside this item which has IsVisible attribute set to false?
    For example: I have a page with several tabs in it. Each tab has a StackLayout with a ListView in it. My goal is to slow down the page load by setting IsVisible=false to every StackLayouts which are not displayed to the user. Do you think it will help?
    What about IsEnabled?

Sign In or Register to comment.