views:

2899

answers:

10

I love programming with and for Windows Presentation Framework. Mostly I write browser-like apps using WPF and XAML.

But what really annoys me is the slowness of WPF. A simple page with only a few controls loads fast enough, but as soon as a page is a teeny weeny bit more complex, like containing a lot of data entry fields, one or two tab controls, and stuff, it gets painful.

Loading of such a page can take more than one second. Seconds, indeed, especially on not so fast computers (read: the customers computers) it can take ages.

Same with changing values on the page. Everything about the WPF UI is somehow sluggy.

This is so mean! They give me this beautiful framework, but make it so excruciatingly slow so I'll have to apologize to our customers all the time!

My Question:

  1. How do you speed up WPF?
  2. How do you profile bottlenecks?
  3. How do you deal with the slowness?

Since this seems to be an universal problem with WPF, I'm looking for general advice, useful for many situations and problems.

Some other related questions:

+5  A: 

Install SP1... Loads of very cool performance increases for WPF!!!

Read more here

Here is a example of 2 enhanchements made in SP1: Deffered scrolling & UI Element recyceling!!!

rudigrobler
The ones you might "notice" first are the scrolling and binding improvements...Read more here: http://dotnet.org.za/rudi/archive/2008/05/22/scrolling-performance-in-wpf.aspx
rudigrobler
+1  A: 

avoiding animations also helps a lot sometimes. if you have to use animations, decrease the framerate, this will improve "Feeled" performance

Joachim Kerschbaumer
+2  A: 

WPF is meant for computers with modern graphics cards. Do your clients have modern graphics cards capable of running Aero? If your clients have older graphics cards, WPF will fall back to software rendering which runs extremely slow in comparison to hardware accelerated graphics.

You also might want to profile your application to make sure that it is actually WPF that is the slow part. It's possible that there is something else that is actually the bottleneck.

jezell
A: 

Hi Sam, can you give more details?

I only noticed a slow performance when I use something like a listview or a grid that has some complexity. The solution is to simplify it.

Other than that I only noticed a slow performance when loading the app for the first time.

HTH

Artur Carvalho
+4  A: 

Dd you try to use the WPF PerfTool instead of the one in VS?

Casper Andersen
+18  A: 
  1. How do you speed up WPF?

    Often after using one of the following profiling tools it is obvious what is causing my bottlenecks.

    • If memory is the issue then I virtualize my data.
    • If render time is the issue then I virtualize the controls or simplify control templates where possible.
    • If processing time is the issue I try to improve my algorithm or move that work to a background thread and show a throbber in my ui while the work is going.

  2. How do you profile bottlenecks?

  3. How do you deal with the slowness?

    Profiling and counseling.

Todd White
What do you mean by "virtualize" the data/controls?
Orion Edwards
(+1) for an excellent answer. However, I think you should expand on 3, because the rest of your answer is so professional. You already partially answered it with 'show throbber in UI', and there are other options such as preloading, sequential rendering, splitting pages, etc. Question 3 is the broader most practical question in an application sense (i.e. UX), and so it deserves some consideration.
By 'virtualizing' the OP means this: for a control with many items (such as a list control), only hold the visible items in memory, never the complete set of items. This saves memory when you have a huge amount of items, as you only have to store as many items as are visible to the user, not the whole set.
Dan
+1  A: 

Remove alpha transparency/ bitmap effects.

A: 

I find it helpful to side-step the XAML, and write the entire UI in C#. This lets me precisely control when the controls are created and loaded. It also helps me understand what XAML is doing "under the covers".

+3  A: 

I can not add comments, that's why I post a new answer to this: I've found this video from the pdc09 that gives some ideas about how to profile wpf apps and because it helped me lot, I want to share the link:

Advanced WPF Application Performance Tuning and Analysis

HCL
Direct2D > WPF :)
DeadMG