PDC 2010: Optimizing Performance for Silverlight Windows Phone 7 Applications

October 31, 2010

Following is a summary of the session “Optimizing Performance for Silverlight Windows Phone 7 Applications” presented by Oren Nachman, Software Developer at Microsoft, in PDC 2010.

image

This session takes what we have learned in the previous session about Windows Phone 7 to the next level.

Oren shows code snippets that actually make a difference and demonstrates very nicely how you can analyze your app to fins performance pitfalls.

Performance

Silverlight Threading on the Phone

Silverlight for phone has a thread named “compositor thread” that removes responsibility off the UI thread, mainly to handle animations. For example when you create an animation that moves a circle, the first rendering of the circle is done on the UI thread and the composer thread handles moving the circle.

image

Performance Debugging

Performance counters:

  1. Composition Thread Frame Rate: how many frames per second are ticking on compositor thread.
  2. UI Thread Frame Rate: how many per second are ticking on UI thread.
  3. Texture Memory Usage
  4. Surface Counter
  5. Intermediate Surface Counter
  6. Fill Rate Counter

Check this article for recommended values and more details for Windows Phone 7 counters.

ListBox

There is a tradeoff between using the StackPanel vs. using a VirtualizedStackPanel inside the ListBox.

The ListBox in Windows Phone 7 by default uses a VirtualizedStackPanel, so not all elements are loaded at once. This is to avoid loading all the elements into the memory (there is a limit on memory utilization of 90mb).
The problem with this method is that scrolling between the items might get a little jerky since items are being loaded as you scroll.

On the opposite end, you can use StackPanel in the ListBox but then loading takes more time since all the elements are loaded in advance.

Another useful tip is instead of binding to an IList that is ready in advance, bind to an ObservableCollection and add items as you go, while the page is already loaded.

Panorama and Pivot

Several tips when you use the Panorama control or Pivot control:

  • Animations on pages that are not seen are still animating and taking performance down the drain.
  • the Panorama control has no virtualization. That means that all pages in the panorama are loaded at once.
  • Delay load if loading is heavy.
  • If you do lots of binding, it is done on all pages. To fix this split your view models to match your views.
  • Finally, don’t optimize if it works fine!

Networking

Prefer using HttpWebRequest on BackgroundThread over WebClient. Since WebClient always post back to the UI thread.

Limit to 6 parallel requests (this is a system limit).

When using WIFI download large chunks in parallel to get better throughput.

Popup

Popup has minimal hardware acceleration, prefer not to use it. Instead you can use a hidden canvas that is just waiting to show.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it
Add comment
facebook linkedin twitter email

Leave a Reply