WPF too slow for Real-time applications?

Jul 30, 2010 at 6:15 PM

Hi,

I am building a WPF GUI that acts like a stock monitor. I am using a DataGrid and using Data Binding to update information. I am experiencing a lot of lags when there are more than one row updating at the same time. I don't have an exact measure of how fasts these updates are, but I would say no more than 10-15 updates per seconds. 

I am surprised I am getting slow down, is WPF not able handle these kind of updates? Is there a feature in DataGrid that can control how many updates it makes per second or something similar? I am just wondering what other people's experience are when using WPF for fast updating front end applications.

Thanks,

Kelvin

Aug 2, 2010 at 9:01 PM
Edited Aug 2, 2010 at 9:01 PM
It's probably not WPF itself that's slow, but rather the WPF Toolkit DataGrid control. This control is notoriously slow. You might want to try a simpler control, or a different DataGrid control like a commercial one or the WinForms DataGridView control via interop.

By the way, there are also WPF performance guidelines and profiling tools available to help you find out why something is slow, if you have the time and inclination to learn and explore how things work at a lower level. For example:

http://msdn.microsoft.com/en-us/library/aa970683.aspx
http://blogs.msdn.com/b/jgoldb/archive/2010/05/21/wpfperf-performance-profiling-tools-for-wpf-4-is-now-available.aspx

Aug 3, 2010 at 10:49 PM

Thanks a lot. What is the commerical DataGrid? Is it the sdk:DataGrid? 

http://msdn.microsoft.com/en-us/library/cc189753(v=VS.95).aspx

I am using VisualStudio 2008 .Net 3.5 SP1. Do I need to install .Net 4.0 to use this?

It's a medium sized software, I would hate to change my structure to use another type of control......

 

either way, thanks a lot, those are very useful information.

Aug 3, 2010 at 11:23 PM
Edited Aug 3, 2010 at 11:23 PM

A DataGrid is typically a complex and powerful control.  Very difficult to develop.  Microsoft did not provide one for WPF until they released the WPF Toolkit DataGrid control, available for .NET 3.5 SP1.  This same control got included in the .NET 4.0 release.  Maybe there were some bugfixes/differences going from the WPF Toolkit version to the .NET 4.0 version, but who knows?  Is it documented anywhere?  I couldn't find such information.

Meanwhile, other companies developed their own DataGrid controls.  This is what I was talking about when I said "commercial".  There are free controls, like the ones that Microsoft provides, then there are commercial ones from other companies that you typically have to pay for.  For more information, see the following (and be sure to also read the questions under "Linked" on the right):

http://stackoverflow.com/questions/144537/what-are-some-good-wpf-grid-controls

You might be able to get better performance by using a different DataGrid control.  Or you might just need to change how you're using the DataGrid control you're using right now.  Or it might be easier to use a simpler control instead, even if you have to restructure your application code.  In any case, it might be useful to find out in more detail why you're experiencing slowdowns.

Aug 3, 2010 at 11:34 PM

That make sense.

Maybe WinForm DataGridView would be a good choice, but I like WPF's other capabilities, in case my app. expands in the future. How about the WPF ListView? Is that a slow/complex control?

Since my GUI is a stock ticker/monitor, it would require pretty fast updates. I would say as much as 20-30 updates per second or more.

Aug 3, 2010 at 11:48 PM

The WPF ListView control is probably a lot simpler than the DataGrid control.  It's only focused on viewing, and I think it has a lot fewer features than DataGrid.  I can't say for sure that it will be faster, only that simpler controls tend to be faster.  Of course, it depends greatly on how they're implemented and how you use them.  It's worth a try, anyway.  Try a simple test program first if it's a lot of work to change your app.

20-30 updates per second should be no problem in WPF if you (and the controls you're using) are doing things efficiently.

By the way, some people debated ListView/ListBox vs. DataGrid a little bit in the questions linked to the question I linked to in my previous post.

Aug 9, 2010 at 8:58 PM
Edited Aug 9, 2010 at 8:58 PM

Perhaps you could provide a screen shot how you'd like it to look. It would be easier to advice with that.

Designing for good performance in WPF is not impossible but not always trivial due to its flexibility and powerful layout engine.

It's hard to come up with a good list of guidelines but I guess I could make a try:

0. Use the simplest possible visualizer (ie is ListBox good enough then it's probably performs better than DataGrid)

1. Use virtualizing stackpanels if you have many (ie >100) rows

2. Use ObservableCollections and minimal rebuild of those

3. Use DataTemplates (enables lazy build of visual tree)

4. Avoid scrollviewers (as they are unbounded and thus instantiate visual objects that's outside the screen, the scrollviewers that's built into ListBox doesn't do this when using virtualizing stackpanel)

5. Use Styles to simpify visual objects (if you have a visual object that's instansiated many times it can make sense to remove unused clutter using Styles)

6. Use a tool to visualize the visual tree or build a simple function that dumps it for you (will help you identify where you have unnecessary complex objects)

7. Use bitmap cache in .NET 4 / Silverlight (but use it smart, ie only on static content or mostly static content, its often possible to separate dynamic content into a static tree and a dynamic tree and cache the static tree)

8. Sometimes the best thing you can do is to override OnRender

There's more of course.