11

I have a few fairly simple animations (moving text around, moving ellipses etc.) and running in full screen (1920x1080 minus the task bar) the WPF Performance Suite reports a good framerate around 50 FPS throughout the animation. Dirty Rect Addition is somewhere around 300 rect/s, the SW frames are between 0 and 4 and the HW frames are between 3 and 5. Video memory usage is around 80 MB.

WPF Performance screen shot

Problem is that the animations stutters every other half second. It is definitely not fluid :-(

My machine is a new Dell laptop XPS 15 with the GeForce GT 435 with 2GB memory. - The drivers are up to date. (The same behavior occurs on my netbook (in full screen) as well so I don't think it is hardware related.)

If I make the window smaller the stutter goes away.

The stutter occurs with the simplest of animations - even with just a couple of elements but adding more elements certainly makes it more noticeable.

How can I find out what causes this stutter?

When I think of it, I have not actually seen any WPF animations which run smoothly in full screen. Is this even possible?

Patrick Klug
  • 14,056
  • 13
  • 71
  • 118
  • Maybe you are repainting too much? I.e. pixels that have not changed between two frames are being marked as dirty even though they are not. – Jonas Kongslund Apr 12 '11 at 16:24
  • 1
    great question! As a test, have you tried leaving only one animated control to see if the stutter continues? if it doesn't, then, how are you updating the data for all controls, meaning is it all on the same thread, or are you spawning tasks /parallel methods and then when they complete update the UI (on UI Thread)? – denis morozov Apr 19 '12 at 15:49
  • 1
    > When I think of it, I have not actually seen any WPF animations which run smoothly in full screen. Aha! WPF is very slow. Best you can do is animate less complex UI, lower framerate or wait for the WTF framework which will solve all these problems ;P – Dr. Andrew Burnett-Thompson Jul 10 '12 at 13:50
  • Does your XPS laptop have the nVidia Optimus setup? I have that on my XPS 15 and noticed that animations weren't nearly as smooth when running on the integrated graphics. Forcing the app to run with the nVidia card instead made a huge difference in performance. – rossisdead Jul 10 '12 at 14:21
  • It seems there is no solution - http://stackoverflow.com/questions/3002271/smooth-text-animation-marquee-using-wpf :( – Goran Sep 20 '12 at 15:08
  • indeed, I gave up on it. It's simply impossible to have a constant framerate or truly smooth animations in WPF. I since moved a lot of my projects to HTML5 and guess what. Animations just work. – Patrick Klug Sep 21 '12 at 03:06
  • @Dr. ABT , what is WTF? – Maria Jun 10 '16 at 12:20
  • It's a joke, I used to say the WPF framework was the WTF framework because of all the crazy things that happen in it :) – Dr. Andrew Burnett-Thompson Jun 10 '16 at 13:18

3 Answers3

8

Have you tried to set a lower "max frame rate" to the animation?

<Storyboard Timeline.DesiredFrameRate="10">
    <!-- ....blah blah blah  -->
</Storyboard>

If your animation is causing massive recalculation of child or parent elements, changing the DesiredFrameRate will have a cascading effect on the number of calculations made by the system. Also, check out the "Remarks" section of this link. It explains why/when you should use it.

If setting a lower frame rate fixes your stuttering, then you need to consider simplifying your XAML to limit the amount of recalculation needed at every frame of your animation (limiting the number of child or parent objects resized - or affected in any way - by every frames/changes made by the animation.

You might want to also check out the "WPF Performance Suite". It is an awesome set of tools to determine what exactly is going on in your WPF app, seeing which parts of your window are being repainted and when, and the CPU usage of each of your XAML elements!

Hope this helps!

John Cummings
  • 1,949
  • 3
  • 22
  • 38
JFTxJ
  • 542
  • 6
  • 17
2

Patrick,

I have no answers. All I can do is provide some solidarity. I'm trying to animate an ItemsControl. The concept is pretty simple, really. I've got a ListView and in the ListView I have a GridView. I want the items in the GridView to to smoothly go from one row to another row as the underlying list is sorted so that, for example, a sorted list will stay sorted as the values in the list change.

I've noticed this: animation on moderately complex controls is a CPU hog. The stuttering I'm pretty sure is simply related to the CPU being maxed out (I noticed you didn't provide the CPU graph on your dump above). Keep the CPU around 50% and the animation appears smooth, above 75% and you get these stutters. Still working on the problem, but I think it goes deeper than my code.

Don

Quark Soup
  • 4,272
  • 3
  • 42
  • 74
0

I had a similar issue where it was stuttering, nothing really major it just looked like little stutters here and there while I ran the program. On a hunch, I shut down Google Chrome while it was running and that fixed it,the scrolling became completely smooth...

So my advice would be if you have any internet browsers open check to see if closing them out fixes the problem.

MattE
  • 1,044
  • 1
  • 14
  • 34