简体   繁体   中英

WPF Animation FPS vs. CPU usage - Am I expecting too much?

Working on a screen saver for my wife, http://cchearts.codeplex.com/ , and while I've been able to improve FPS on lower end machines the CPU usage still seems very high.

Here's some numbers I ran from a few 5 minute sampling periods:

~60FPS 35% average CPU on Core 2 Duo T7500 @ 2.2GHz, 3GB ram, NVIDIA Quadro NVS 140M (128MB), Vista [My dev laptop]

~40FPS 50% average CPU on Pentium D @ 3.4GHz, 1.5GB ram, Standard VGA Graphics Adapter (unknown), 2003 Server [A crappy desktop]

I can understand the lower frame rate and higher CPU usage on the crappy desktop but it still seems pretty high and 35% on my dev laptop seems high as well.

I'd really like to analyze the application to get more details but I'm having issues there as well so I'm wondering if I'm doing something wrong (never profiled WPF before).

WPF Performance Suite:

Process Launch Error

Unable to attach to process: CCHearts.exe Do you want to kill it?

This error message occurs when I click cancel after attempting launch. If I don't click cancel it sits there idle, I guess waiting to attach.

Performance Explorer:

Could not launch C:\\Projects2\\CC.Hearts\\CC.Hearts\\bin\\Debug (USEVISUAL)\\CCHearts.exe. Previous attempt to profile the application finished unsuccessfully. Please restart the application.

Output Window from Performance:

Profiling started. Profiling process ID 5360 (CCHearts). Process ID 5360 has exited. Data written to C:\\Projects2\\CC.Hearts\\CCHearts100608.vsp. Profiling finished. PRF0025: No data was collected. Profiling complete.

So I'm stuck wanting to improve performance but have no concrete way to determine where the bottleneck is. Have been relatively successful throwing darts at this point but I'm beyond that now :)


Summary:

Lot's of progress so far...

Performance Explorer

Problem: Wasn't working, vague error message.

Solution: Used thecommand line version to get a real error message that pointed me to this thread pointing out that it was a Symantec dll blocking me. Setting the following registry key fixed the problem:

[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\SysPlant]

"Start"=dword:00000004

WPF Performance Suite

Problem: Wasn't working, no error message.

Solution: Use the WPF Performance Suite designed for .NET 4 from the Windows SDK 7.1 instead of the previous version from Windows SDK 7 (I feel silly :-P)

WPF Animation

Problem: High CPU usage compared to FPS/percieved workload.

Solution: Lots ok tweaks here and there. But the HUGE improvement was Cached Composition as pointed out by Jeremiah Morrill. Check out the changesets .

I downloaded your code and saw ~20-28% CPU usage on my quad-core 2.6ghz. By adding cached composition, I was able to get it down to ~6-8% CPU.

I compiled using "DEBUG", not "DEBUG(USEVISUAL)" and in Heart.xaml I added the BitmapCache to the Path:

Path CacheMode="BitmapCache" ...

You don't want to overlly optimize. The first question that needs to be answered is what are most screensavers performance?

If everything takes 50% CPU then I would not worry (I doubt that is the case). If you want to save cycles the best before just blindly throw darts make sure you really understand the 3D aspects of WPF.

Here is the best place to start

Maximize WPF 3D Performance

I noticed a similar steady high CPU usage (~95%) on a Celeron 1.1Ghz, but I never noticed any performance degradation as a result of turning on the animation. I never quantified the FPS, though I suspect it was pretty low. My impression is that WPF follows an opportunistic resource utilization strategy, taking what it can to get the best quality it can muster, but not so much that it interferes with other processing. If you load up the CPU with other tasks, I suspect the CPU usage associated with the graphics will drop accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM