Skip to content
十一月 2, 2009 / wychi

DataVirtualization Study

Showing data collection in WPF is quite easy. All you need to do is to prepare your data collection and assign it to ItemsControl.ItemsSource.

But, when we target on a lager set of data (ex: 100k items with complex data template.), here comes the performance issues if you don’t handle it carefully.

First, it might be time-consuming to create 100k items in one time. So you will suffer the first UI sluggish here. (Of course you can use a worker thread to create the data to avoid this sluggish.)

Then you assign the collection to ItemsControl. The WPF layout system will create UI objects for items. Here the second UI sluggish occurs.

If your app doesn’t consume too many memory, you are good from here. But, generally, the overall memory consumption is pretty high now and make the whole application become less responsive.

The goal of virtualization is to minimize the resource usage (ex:computation power / memory ). Consume resource when only necessary.

Virtualization is also a key to scaliblity. Think about the 100k items. No matter how fast an operation is, it won’t fast enough when it times 100k.

We do need a way to get rid of influence of numbers.



Roughly, according to the place of virutalizing skills apply, we can divide them into two categories, UI virtualization and Data virtualization

UI Virtualization

In .Net 3.5, WPF provides UI virtualization to ease the pain of handling large data set.

  1. Virtualizaing Panel
  2. Recycling

You can make your itemsControl’s panel as a virtualizing panel. By doing so, the layout system will create only the visible items during the layout pass.

Then you can tell the ItemContainerGenerator to reuse the created UI objects by enable the recycling mode to save the time of expanding DataTemplate.

Here is a good start serial. Follow this series, Implementing a virtualized panel in WPF, you are able to create your own virtualizing panel.

(Note: There is an enhance chance at MeasureOverride() function. Please pay more attention to that function.)

Having a built-in UI virtualization support is a pretty good thing. It does improve the performance alot. But only in UI level, it is not good enough.

If the bottleneck is at data level,the UI virtualization can’t help here. Then we are still suffering the bad performance.

Data Virtualization

In data level, we don’t have Microsoft’s support. We are on our own now.

There are already four great posts about WPF data virtualization.

After read through those posts, you can get a better understanding about what data virtualization is, what problems might happen and how it fits to WPF.

Those solutions have the same limitation. That is the data collection is read-only. CollectionChanged event is not well-handled. Please Bea Stollnitz’s post for more details.



So far as I study, to introduce data virtualization, you have to deal with these issues.

  1. Virtualize your data / cache mechanism
  2. Selection (Select limited items / select all)
  3. implement your own VirtualizingPanel
  4. CollectionChanged notification.
  5. Grouping / Sorting / Filtering

In implement part, you might need to create your own classes for more detailed controls.

  1. Collection
  2. CollectionView
  3. ItemsControl
  4. VirtualizingPanel
  5. ItemContainerGenerator

I’m going to implement my own version of WPF data virtualization.

Hopefully I extend the existing solution.



在下方填入你的資料或按右方圖示以社群網站登入: Logo

您的留言將使用 帳號。 登出 /  變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )


您的留言將使用 Facebook 帳號。 登出 /  變更 )


連結到 %s

%d 位部落客按了讚: