WP7 Performance

5,792 views

Published on

Slides from my presentation at the Dallas .NET User Group on 2/10/2011

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,792
On SlideShare
0
From Embeds
0
Number of Embeds
387
Actions
Shares
0
Downloads
52
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • 1 GHz sounds like a lot more than it is … Shared CPU, Less RAM, slower IO
  • Composition Thread Frame RateThis value refers to the rate at which the screen is updated. It also represents how often supported animations driven by a storyboard are updated. This value should be as close to 60 as possible. Application performance begins to degrade when this value is below 30. The text in this counter is red when displaying a value below 30.UI Thread Frame RateThis value refers to the rate at which the UI thread is running. The UI thread drives input, per-frame callbacks, and any other drawing not handled by the composition thread. The larger this value, the more responsive your application should be. Typically this value should be above 20 to provide an acceptable response time to user input. The text in this counter is red when displaying a value below 30.Texture Memory UsageThis value represents the video memory and system memory copies of textures being used in the application. This is not a general memory counter for the application, but represents only memory that surfaces use.Surface CounterThis value provides a raw count of the explicit surfaces being passed to the GPU for processing. The biggest contributor to this number is automatic or developer-cached elements.Intermediate Surface CounterThis value represents the implicit surfaces generated as a result of cached surfaces. These surfaces are created in-between UI elements so that the application can accurately maintain the Z-order of elements in the UI.Fill Rate CounterThis value represents the number of pixels being painted per frame in terms of screens. A value of 1 represents 480 x 800 pixels. The recommended value is about 2.5. The text in this counter turns red when displaying a value above 3.
  • StackPanel will improve scrolling performance but decrease loading performance
  • WP7 Performance

    1. Windows Phone 7 Performance Tips<br />Chris Koenig<br />Senior Developer Evangelist<br />Microsoft Corporation<br />@chriskoenig | chriskoenig.net | chris.koenig@microsoft.com<br />
    2. SUN SHADE<br />If only you could <br />attach it to a hat<br />verydemotivational.com<br />
    3. delicious.com/chriskoenig<br />/wp7+performance<br />
    4. Windows Phone<br />Silverlight 3 <br />Optimizations for <br />DirectX 9 GPU<br />Touch, 800x480 display<br />1 GHz ARM Scorpion<br />
    5. UI Threading Models<br />Desktop (up to SL4, today) <br />UI thread <br />Input <br />Layout + Render<br />Events + Binding<br />Animation<br />Rasterize <br />Windows Phone<br />UI thread <br />Input<br />Render + Layout <br />Events + Binding <br />Some Animation<br />Rasterize <br />Compositor thread <br />Basic Animation <br />Draw buffers<br />
    6. Threading Models<br />UI Thread <br />vs. <br />Compositor Thread<br />
    7. Desktop to Mobile (mindset) <br />~1 GHz is not that much <br />User expects immediacy<br />Network latencies are high <br />Small Screen = More transitions <br />Touch is primary input <br />Preserve battery life<br />
    8. Basic Rules of Thumb<br />Perceived vs. Actual Performance<br />How slow is slow?<br />Performance vs. Complexity<br />Identify potential problem areas<br />Monitor as changes are made<br />Test on a device early and often<br />Involve designers early and often<br />
    9. Startup Performance Tips<br />Use a Splash screen<br />Keep assemblies small <br />Partition assemblies<br />Include media as Content, not as Resources<br />Use Satellite assemblies<br />Delay load assemblies <br />Avoid ApplicationSettingsclass<br />Be granular, choose faster formats <br />Delay load content (esp. Panorama, avoid Item parsing)<br />
    10. Navigating to an External Resource<br />private void button1_Click(object sender, RoutedEventArgs e) <br />{ <br />var s = "/OtherAssembly;component/ExternalPage.xaml"<br />varuri = new Uri(uriString, UriKind.Relative); <br />NavigationService.Navigate(uri);<br />}<br />
    11. Using LayoutUpdated<br />private bool _onNavigatedToCalled = false; <br />public Page() { <br />InitializeComponent(); <br />LayoutUpdated+= new EventHandler(Page_LayoutUpdated); <br />} <br />protected override void OnNavigatedTo(NavigationEventArgse) {<br /> _onNavigatedToCalled = true; <br />} <br />private void Page_LayoutUpdated(object sender, EventArgs e) { <br />if (_onNavigatedToCalled == true) { <br /> _onNavigatedToCalled = false; <br />Dispatcher.BeginInvoke(() => { DoWork() } ); <br />} <br />} <br />
    12. UI Performance Tips<br />Less is more<br />Minimize UI thread work<br />Leverage the GPU<br />Opacity vs. Visibility <br />BitmapCache<br />Never ever use OpacityMask<br />Use Manipulation Events over Mouse Events<br />
    13. UI - Things to Avoid<br />Color Animation<br />Non-rectangular clips<br />Opacity masks<br />Popup<br />Converters<br />Watch for Callbacks that come back to UI thread<br />e.g. WebClient, GeoCoordinateWatcher, etc.<br />
    14. BitmapCacheCacheMode=“BitmapCache”<br />Useful for…<br />Render Transform<br />Scale Transform<br />Rotate Transform<br />Translate Transform<br />Change the opacity<br />Change the clipping region<br />Danger Areas<br />Caches Bitmaps – not Vectors!<br />You will lose fidelity<br />Try different RenderAtScale<br />Items frequently redrawn<br />Non-rectangular clips<br />
    15. Performance Counters<br />Composition Thread FPS<br />UI Thread FPS<br />Texture Memory Usage<br />Surface Counter<br />Intermediate Surface Counter<br />Screen Fill Rate Counter<br />
    16. UI Performance<br />BitmapCache<br />FillRateTest<br />
    17. ListBox Performance Tips<br />Don’t load so darn much data!<br />Simplify ListBoxItemTemplate<br />Avoid converters on bindings <br />Load images in the background (LowProfileImageLoader)<br />Use Data Virtualization (e.g. LazyListBox)<br />ListBox alternatives<br />StackPanel for short lists<br />LongListSelector for complex lists<br />LazyListBox + LowProfileImageLoader for alt. templates<br />
    18. Control Alternatives<br />PerformanceProgressBar<br />LowProfileImageLoader<br />LongListSelector<br />LazyListBox<br />DeferredLoadListBox<br />DeferredLoadStackPanel<br />GroupingItemsControlConverter<br />
    19. Custom Controls<br />PerformanceProgressBar<br />LowProfileImageLoader<br />LazyLoadListBox<br />VirtualizingDataTest<br />
    20. Data Performance Tips<br />Consider network latency<br />Consider impact of holding data in memory<br />Parallelize data requests to save battery<br />Process data on background threads*<br />Use HttpWebRequest instead of WebClient<br />
    21. Media<br />Use Jpeg over Png whenever possible<br />Use Images over Xaml whenever possible<br />Limit image size to 2K x 2K<br />Set Build Action to Content<br />Encode media for optimal playback rate and resolution<br />
    22. Fast is not good enough!! <br />Perceived performance is important! <br />Feedback on clicks <br />ProgressBar (use Jeff Wilcox) <br />Transitions across pages <br />That said,<br />Don’t rely on our magic. <br />Use the counters and flags to verify. <br />Balance ‘feedback’ with real work ... <br />
    23. Summary<br />How slow is slow?<br />Plan ahead for problem areas<br />Utilize the counters<br />Test, test, test – especially on a device<br />
    24. chriskoenig.net/WP7Resources<br />
    25. Credits<br />Thanks to Jaime Rodriguez, YochaiKiriati, Jeff Wilcox, Peter Torr and all the other great presenters, speakers and bloggers from whom I found all this great content about performance tuning Silverlight applications for Windows Phone 7.<br />

    ×