Silverlight application performance - refresh rate & CPU usage - DevCorner

Silverlight application performance - refresh rate & CPU usage

You just wrote great Silverlight application? How about CPU usage? Do you have pretty static application UI and it still consumes 25-30% of your CPU? Probably you have to control how fast Silverlight should redraw the UI.

To do it, you need to specify MaxFrameRate property in object initialization, like follows:

   1: <asp:Silverlight ID="Xaml1" runat="server" 
   2:     Source="~/ClientBin/ShowFPS.xap" 
   3:     MinimumVersion="2.0.30523" 
   4:     Width="100%" Height="100%"             
   5:     MaxFrameRate="30" 
   6: />

Default value is 60fps, which is pretty high and will made animations looks very smooth. But if you application doesn't have much animations, or your UI is not changing much? Why not limit it to some acceptable value? Even if you application play video stream the MaxFrameRate shouldn't be much faster, than encoded stream rate. NTSC video encoded at 29.92fps, average on-demand video streams encoded at 15fps - why not limit your application at 30fps? To demonstrate the difference I've wrote sample application, with VERY dynamic UI: it has bouncing ball (which is actually canvas with many path objects inside) animation and video (Vista's sample "Butterfly.wmv" encoded at 29fps) played at a background. I'm also have some storyboard running which actually enables me to move ball canvas and calculate/update framerate.

Here is unrestricted framerate screenshot:

60fps

59-60fps according to calculations, 25-30% CPU.

Here is the same application with MaxFrameRate applied:

30fps

29-30fps(exactly like we wanted), 12-15% CPU load. Video is very smooth, animation is also smooth, bit plays slower.

Here is same application at 15fps:

15fps

14-15fps(exactly like we wanted), 6-10% CPU load. Video is still pretty smooth, but "jumps" sometime. For local played file it could be visible, but for network stream it is pretty acceptable.

So, next time when writing Silverlight application, consider specifying MaxFrameRate to ease on CPU.

 

Another nice feature of Silverlight plugin - show actual/desired framerate. To enable it add EnableFrameRateCounter="true" in object definition:

   1: <asp:Silverlight ID="Xaml1" runat="server" 
   2:     Source="~/ClientBin/ShowFPS.xap" 
   3:     MinimumVersion="2.0.30523" 
   4:     Width="100%" Height="100%" 
   5:     EnableFrameRateCounter="true"            
   6:     MaxFrameRate="30" 
   7: />

(*) This will work only in IE.

 

Here is couple more of performance tips:

1. IsWindowless ="false" is faster. Unless you application requires overlay of HTML content on top of Silverlight, don't turn it on.

2. Use solid/opaque background for Silverlight HTML object - it is faster.

3. Try to avoid usage of transparent/semi-transparent colors for XAML controls.

4. Use Visibility="Collapsed" instead of Opacity=0 to hide XAML control.

 

That's it for now.

 

Implementation of Silverlight FPS counter and/or application sources could be found here.

 

Enjoy,

Alex

Comments

# re: Silverlight application performance - refresh rate & CPU usage

Cool!

I've been looking on different tips on SL object for long!!

Thanks

Thursday, July 17, 2008 8:10 PM by Bora

# Silverlight Cream for July 17, 2008 -- #327

Denislav Savkov on VSM, Mino with a SL PhotoGallery, Alex Golesh on app performance, Avi Pilosof with

Thursday, July 17, 2008 10:21 PM by Community Blogs

# cpu id | computer tags

Pingback from  cpu id | computer tags

Friday, July 18, 2008 3:02 AM by cpu id | computer tags

# 100% cpu usage | computer tags

Pingback from  100% cpu usage | computer tags

Friday, July 18, 2008 7:19 PM by 100% cpu usage | computer tags

# definition of a cpu | computer tags

Pingback from  definition of a cpu | computer tags

Friday, July 18, 2008 10:03 PM by definition of a cpu | computer tags

# definition of cpu | computer tags

Pingback from  definition of cpu | computer tags

Friday, July 18, 2008 11:13 PM by definition of cpu | computer tags

# cpu usage 100% | computer tags

Pingback from  cpu usage 100% | computer tags

Friday, July 18, 2008 11:36 PM by cpu usage 100% | computer tags

# Post: 143

Post: Approved at: Jul-18-2008 Performance - Refresh Rate &amp; CPU Usage Why waste my CPU than you need

Saturday, July 19, 2008 12:01 AM by Mirrored Blogs

# high cpu usage | computer tags

Pingback from  high cpu usage | computer tags

Saturday, July 19, 2008 2:43 AM by high cpu usage | computer tags

# cpu speed comparison | computer tags

Pingback from  cpu speed comparison | computer tags

Saturday, July 19, 2008 3:29 AM by cpu speed comparison | computer tags

# Silverlight news | Enetlive.net- Rich Internet Applications Blog

Pingback from  Silverlight news | Enetlive.net- Rich Internet Applications Blog

# Samples from the Silverlight community

Pingback from  Samples from the Silverlight community

Thursday, July 24, 2008 10:05 PM by Samples from the Silverlight community

# wan acceleration technologies

This way when you install all of these parts that you have purchased from a car audio wholesale dealer you have the assurance that you will not need to buy any other part at least for a while. With this information you can make sure that when you go to

Thursday, January 08, 2009 11:18 AM by wan acceleration technologies

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: