WPF Animation FPS vs. CPU usage - Am I expecting too much?
- by Cory Charlton
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 (switch from Path to StreamGeometry, use DrawingVisual instead of UserControl, etc) 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 :)
PS: Screensaver is hosted at CodePlex if you want to look at the source and missed the link above.
Edit: My RenderOptions darts...
// NOTE: Grasping at straws here ;-)
RenderOptions.SetBitmapScalingMode(newHeart, BitmapScalingMode.LowQuality);
RenderOptions.SetCachingHint(newHeart, CachingHint.Cache);
RenderOptions.SetEdgeMode(newHeart, EdgeMode.Aliased);
I threw those a little while back and didn't see much difference (not sure if the bitmap scaling even comes into play). Really wish I could get profiling working to know where I should try to optimize. For now I assume there is some overhead in creating a new HeartVisual and the DrawingVisual contained inside. Maybe if I reset and reused the hearts (tossed them in a queue once they completed or something) I'd see an improvement. Shrug Throwing darts while blindfolder is always fun.