WPF: Improving Performance for Running on Older PCs

Posted by Phil Sandler on Stack Overflow See other posts from Stack Overflow or by Phil Sandler
Published on 2010-04-23T13:33:21Z Indexed on 2010/04/23 16:03 UTC
Read the original article Hit count: 259

So, I'm building a WPF app and did a test deployment today, and found that it performed pretty poorly. I was surprised, as we are really not doing much in the way of visual effects or animations.

I deployed on two machines: the fastest and the slowest that will need to run the application (the slowest PC has an Intel Celeron 1.80GHz with 2GB RAM). The application ran pretty well on the faster machine, but was choppy on the slower machine. And when I say "choppy", I mean the cursor jumped even just passing it over any open window of the app that had focus.

I opened the Task Manager Performance window, and could see that the CPU usage jumped whenever the app had focus and the cursor was moving over it. If I gave focus to another (e.g. Excel), the CPU usage went back down after a second. This happened on both machines, but the choppiness was only noticeable on the slower machine. I had very limited time to tinker on the deployment machines, so didn't do a lot of detailed testing.

The app runs fine on my development machine, but I also see the CPU spiking up to 10% there, just running the cursor over the window.

I downloaded the WPF performance tool from MS and have been tinkering with it (on my dev machine). The docs say this about the "Frame Rate" metric in the Perforator tool:

For applications without animation, this value should be near 0.

The app is not doing any heavy animation, but the frame rate stays near 50 when the cursor is over any window. The screens I tested on have column headers in a grid that "highlight" and buttons that change color and appearance when scrolled over. Even moving the mouse on blank areas of the windows cause the same Frame rate and CPU usage (doesn't seem to be related to these minor animations).

(Also, I am unable to figure out how to get anything but the two default tools--Perforator and Visual Profiler--installed into the WPF performance tool. That is probably a separate question).

I also have Redgate's profiling tool, but I'm not sure if that can shed any light on rendering performance.

So, I realize this is not an easy thing to troubleshoot without specifics or sample code (which I can't post). My questions are:

  • What are some general things to look for (or avoid) in the code to improve performance?
  • What steps can I take using the WPF performance tool to narrow down the problem?
  • Is the PC spec listed above (Intel Celeron 1.80GHz with 2GB RAM) too slow to be running even vanilla WPF applications?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about rendering