Silverlight performance with many loaded controls
Asked Answered
B

4

10

I have a SL application with many DataGrids (from Silverlight Toolkit), each on its own view. If several DataGrids are opened, changing between views (TabItems, for example) takes a long time (few seconds) and it freezes the whole application (UI thread).

The more DataGrids are loaded, the longer the change takes. These DataGrids that slow the UI chanage might be on other places in the app and not even visible at that moment. But once they are opened (and loaded with data), they slow showing other DataGrids. Note that DataGrids are NOT disposed and then recreated again, they still remain in memory, only their parent control is being hidden and visible again.

I have profiled the application. It shows that agcore.dll's SetValue function is the bottleneck. Unfortunately, debug symbols are not available for this Silverlight native library responsible for drawing.

The problem is not in the DataGrid control - I tried to replace it with XCeed's grid and the performance when changing views is even worse.

Do you have any idea how to solve this problem? Why more opened controls slow down other controls?

I have created a sample that shows this issue: VS solution, live demo

UPDATE: Using VS11 profiler on the sample provided suggests that the problem could be in MeasureOverride being called many times (for each DataGridCell, I guess). But still, why is it slower as more controls are loaded elsewhere? Is there a way to improve the performance?

UPDATE 2: I should mention that I don't use TabControl in my particular application. I use Caliburn.Micro and ContentControl to show currently active ViewModel. But the same issue is with TabControl so I used it to describe the core problem.

Bolingbroke answered 18/3, 2012 at 13:1 Comment(7)
See the discussion here (the bit about TabControl), it may help: #1390269Tanhya
Actually, in my original application, I use Caliburn.Micro (MVVM framework) so instead of a TabControl, I have a ContentControl bound to currently active ViewModel (and thus its View). Nevertheless, I'll check the discussion and let you know. Thank you!Bolingbroke
@Tanhya The suggested solution does not work in my case :-(Bolingbroke
Have you considered subclassing the tab control and overriding MeasureOverride?Dewan
You're using CM for the real app but the PerfTest doesn't?Erythrism
@DerekBeattie Yes, as it seems to be more of Silverlight problem, I wanted to show the core SL issue.Bolingbroke
I see, I was curious as to how you load the data, since with CM you've got some lifecycle with each screen.Erythrism
B
5

So, I followed the idea of creating custom control and here is the result: http://www.baud.cz/blog/fast-switching-between-viewmodels-in-caliburn.micro.

Quick links to MVVM demo applications: Original and Fixed

Bolingbroke answered 27/3, 2012 at 13:34 Comment(2)
+1. This is what we ended up doing in one project. We had the same setup TabControl with lost of visual and we also used Caliburn. And the solution was to cache and return cached views with IViewAware.GetViewLeonardo
AFAIK, IViewAware.GetView in Caliburn.Micro already caches the views. I think one can tell by changing views in TabControl where scrollbar position persists (this is not saved in VM).Bolingbroke
F
0

We experienced something similar to this, we were loading many heavy control-laden user controls dynamically and the more that were rendered the slower the app seemed to be. As crazy as it sounds, when we set the layout root of each control to a Border control the performance issues subsided significantly as the layout system didn't have to fight as hard to update all of the resources.

Just wanted to share something that worked a miracle for us that you could try.

Factorage answered 21/3, 2012 at 23:54 Comment(0)
J
0

This is a semi-wild guess, but I wonder if it would help to set Visibility to Collapsed on tabs that aren't selected. (I assume row virtualization is enabled on the DataGrid. That's helped me a lot in the past.)

My semi-wild guess is based mostly on this tip and on my intermediate understanding of the information found here.

Jeromejeromy answered 22/3, 2012 at 17:25 Comment(2)
I actually rewrote the sample provided in using MVVM and showing the active content in a ContentControl which used a converter to render the views with only one active and it still was slow.Metallist
@Metallist that is exactly my problem. I just used TabControl to simplify it as possible. The possible solution I can see is to create a custom ContentControl (probably based on ItemsControl) that would besides active item somehow hold the other views so that they are not removed from visual tree and thus not require recreating them again when the respective view is activated.Bolingbroke
G
0

I had this issue with c1DataGrid, I found that after turning themes off, changing tabs was fast, and doing other UI operations were instant.

Also try:

  1. Ensure that none of your code is being called by stepping through with VS.
  2. Remove all applied styles
  3. if still slow eliminate component by component, maybe its not just the data grid
  4. replace your datagrid with c1datagrid
Gerhardt answered 23/9, 2013 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.