none
Amount of Controls & Memory / Performance

    Question

  • We are currently in a first phase of our project where we'll create some custom controls.
    During performance tests we experienced some big performance and memory issues.

    Our first thougth was that the custom controls are the issue. Therefore we replaced them by standard TextBox-Controls - same problems.

    The test program consists of a TabControl with about 10 TabItems where each them houses 144 TextBox-Controls.
    So we got a total control count of 1440.

    As we're planing to build a huge client framework for a business application, this amount of controls should be no problem.

    With this little test program we exceed our specifications regarding allocated memory (around 200 MB max) by 100 MB.
    And performance while switching between Tabs is horrible (around 1-2 second @ first switch).

    Does anyone know the limitations of Silverlight regarding memory and performance in context of the amount of controls on screen?

    Tuesday, May 03, 2011 9:44 AM

Answers

  • Hi QSC_Austria,

    I have downloaded the project you provided. In your case, all ListBoxItems are displayed on the screen at one time, so UI virtualization doesn't help. Because what UI vistualization do is that it dynamically create ListBoxItemContainer when a ListBoxItem is visible and discard it when it is invisible on the screen.

    Another way you can try is using TextBlock to display value at first time, and convert it to TextBox in TextBlock's MouseLeftButtonDown event handler. TextBlock uses fewer memory than Textbox.

     

    Best Regards,

    Tuesday, May 10, 2011 3:00 AM
  • Hi QSC_Austria,

    I mean by default all fields are displayed in TextBlock and when user click on a TextBlock, the TextBlock is collapsed and a TextBox is inserted at that place(insert using index of stackpanel children) with the value of the TextBlock. Then in LostFocus event handler of TextBox, set TextBlock visible on the screen with TextBox's Text value and remove TextBox from VisualTree later. This is because TextBox is mainly used for editing and i assume that user can only edit one field at one time. You may need to modify it according to your business scenario.

     

    Best Regards,

    Wednesday, May 11, 2011 4:48 AM

All replies

  • use virtualization

    Tuesday, May 03, 2011 9:52 AM
  • Can you explain this a little more detailed? What do you mean with virtualization?

    Wednesday, May 04, 2011 1:57 AM
  • Wednesday, May 04, 2011 2:02 AM
  • Thanks for that link, but as I understood UI Virtualization is only available for ItemsControl (ListBox, ComboBox, ...) and not for normal TextBoxes or Custom Controls.

    Or is this possible too?
    Can you give me a short example how my XAML has to look like? 

    Wednesday, May 04, 2011 2:47 AM
  • it is possible for textboxes and custom controls also

    Wednesday, May 04, 2011 3:00 AM
  • But how would be the XAML-code for a page with 10 TextBoxes that use it?

    Already tried to figure it out by myself, but I can't get it to work...

    Wednesday, May 04, 2011 3:04 AM
  • it is possible for textboxes and custom controls also

    can you give me a more detailed answer? We are desperatly searching for an answer on this topic...

    Thursday, May 05, 2011 7:48 AM
  • Hi QSC_Austria,

    Does anyone know the limitations of Silverlight regarding memory and performance in context of the amount of controls on screen?

    I suggest you only add control to a TabItem when the TabItem is selected and visible on the screen and remove controls from VisualTree when a TabItem is collapsed. Then the UI controls will not take many memory.  

    Additionly, please check the link below for other Silverlight Performance Tips

    http://msdn.microsoft.com/en-us/library/cc221411%28VS.95%29.aspx

     

    Best Regards,

    Sunday, May 08, 2011 10:39 PM
  • Hi Shi Ding,

    i'll have a look at the link you posted, thanks for that!


    We've already tried to instantiate only controls that are currently visible. But then we encountered heavy performance issues.

    Instantiating 150 TextBoxes when switching to another TabItem costs about 2 seconds which gives a bad look&feel for the user.

    Could we try another approach? Any Silverlight Framework functions?

    Monday, May 09, 2011 2:30 AM
  • Hi QSC_Austria,

    Not sure how these 150 TextBox are used and displayed in your project, but could you embed TextBox to Listbox or DataGrid. Because ListBox and DataGrid implements UI Virtualization and it will dramatically improve the preformance.

     

    Best Regards,

    Monday, May 09, 2011 2:40 AM
  • Hi Shi Ding,
    ok now I’ve embedded all the TextBoxes in a ListBox, but I don’t see any difference whether at performance or used memory.

    I’ve prepared a little project for you to show you exactly what I am doing.

    Some details on the project:
    The TabControl stands for our client, where every TabItem is a program running in that client.
    By clicking the button „start program“ a new „Program“ (=TabItem) is created and attached to the TabControl „Client“.

    Every single program has 10 TabItems each containing 144 TextBoxes.

    When you click through Tab0 to 9 you will notice a delay which I relate to a performance issue.
    On the other hand the memory usage will rise, despite only 144 TextBoxes are visible! Starting the GarbageCollector manually (button „GC“) doesn’t change anything. Memory usage will decrease when you close the „Program“ (button „close all programs“).

    In case you are wondering what's the purpose of a TabControl having over 100 TextBoxes... It's just a performance test for our coming project. In our client's current version we have use WinForms under VB.net where some programs running in that client do have about 150-200. As our upcoming version is planned to be in Silverlight we must simulate such programs to see performance and memory usage.

    I hope this project will help you to understand my problems regarding memory and performance better and may lead to a satisfying solution.

    Here the download link: http://www.file-upload.net/download-3417581/PerformanceTest.zip.html

    Monday, May 09, 2011 4:38 AM
  • Hi QSC_Austria,

    I have downloaded the project you provided. In your case, all ListBoxItems are displayed on the screen at one time, so UI virtualization doesn't help. Because what UI vistualization do is that it dynamically create ListBoxItemContainer when a ListBoxItem is visible and discard it when it is invisible on the screen.

    Another way you can try is using TextBlock to display value at first time, and convert it to TextBox in TextBlock's MouseLeftButtonDown event handler. TextBlock uses fewer memory than Textbox.

     

    Best Regards,

    Tuesday, May 10, 2011 3:00 AM
  • Can you explain what you mean with "convert TextBlock into TextBox"?

    Do you mean a custom control that consists of a TextBlock and a TextBox on 2 Tabs which can be switched when needed?

    Wednesday, May 11, 2011 4:08 AM
  • Hi QSC_Austria,

    I mean by default all fields are displayed in TextBlock and when user click on a TextBlock, the TextBlock is collapsed and a TextBox is inserted at that place(insert using index of stackpanel children) with the value of the TextBlock. Then in LostFocus event handler of TextBox, set TextBlock visible on the screen with TextBox's Text value and remove TextBox from VisualTree later. This is because TextBox is mainly used for editing and i assume that user can only edit one field at one time. You may need to modify it according to your business scenario.

     

    Best Regards,

    Wednesday, May 11, 2011 4:48 AM
  • Thanks a lot for your help!

    Instancing the TextBoxes at Runtime leads to much better performance and less memory usage. Smile

    Thursday, May 12, 2011 10:20 AM