开发者

WPF: Improving Performance for Running on Older PCs

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?


Are you applying any BitmapEffect-s to your UI elements? They are not handled by GPU, so CPU takes care of rendering them. If not used properly (e.g. having a OuterGlowBitmapEffect applied to a large complex element) they can have terrible impact on performance.

Also, you still might want to try profiling your app with a performance profiler. Just to see if it's not your code that causes this.


This is not normal for WPF - I'd suspect one of your developers has written code that runs a timer in the background (or more likely given your description, a mouse move handler) which is affecting the UI in some way.

If you have ANTS performance profiler (it's really nice) I'd run that over your app and reproduce the problem.

Once you've done that, ANTS should tell you fairly quickly what the problem is. If ANTS doesn't reveal anything at all, and shows you that in fact none of your code is running during this time, then I'd suspect buggy graphics card drivers.

You can test for this by disabling hardware acceleration by setting the following registry key, and trying again:

HKEY_CURRENT_USER\Software\Microsoft\Avalon.Graphics\DisableHWAcceleration to 1

Note: the DisableHWAcceleration value should be a DWORD

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜