wp7 performance

25
Windows Phone 7 Performance Tips Chris Koenig Senior Developer Evangelist Microsoft Corporation @chriskoenig | chriskoenig.net | [email protected]

Upload: chris-koenig

Post on 20-May-2015

5.199 views

Category:

Technology


1 download

DESCRIPTION

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

TRANSCRIPT

Page 1: WP7 Performance

Windows Phone 7 Performance TipsChris KoenigSenior Developer EvangelistMicrosoft Corporation

@chriskoenig | chriskoenig.net | [email protected]

Page 2: WP7 Performance

verydemotivational.com

If only you could attach it to a hat

SUN SHADE

Page 3: WP7 Performance

delicious.com/chriskoenig/wp7+performance

Page 4: WP7 Performance

Windows Phone

Optimizations for DirectX 9 GPUTouch, 800x480 display1 GHz ARM Scorpion

Silverlight 3

Page 5: WP7 Performance

UI Threading ModelsDesktop (up to SL4, today) • UI thread

– Input – Layout + Render– Events + Binding– Animation– Rasterize

Windows Phone• UI thread

– Input– Render + Layout – Events + Binding – Some Animation– Rasterize

• Compositor thread – Basic Animation – Draw buffers

Page 6: WP7 Performance

Threading ModelsUI Thread vs. Compositor Thread

Page 7: WP7 Performance

Desktop to Mobile (mindset) • ~1 GHz is not that much • User expects immediacy• Network latencies are high • Small Screen = More transitions • Touch is primary input • Preserve battery life

Page 8: WP7 Performance

Basic Rules of Thumb• Perceived vs. Actual Performance– How slow is slow?

• Performance vs. Complexity• Identify potential problem areas• Monitor as changes are made• Test on a device early and often• Involve designers early and often

Page 9: WP7 Performance

Startup Performance Tips• Use a Splash screen• Keep assemblies small

– Partition assemblies– Include media as Content, not as Resources– Use Satellite assemblies

• Delay load assemblies • Avoid ApplicationSettings class

– Be granular, choose faster formats

• Delay load content (esp. Panorama, avoid Item parsing)

Page 10: WP7 Performance

Navigating to an External Resource

private void button1_Click(object sender, RoutedEventArgs e) {

var s = "/OtherAssembly;component/ExternalPage.xaml"var uri = new Uri(uriString, UriKind.Relative); NavigationService.Navigate(uri);

}

Page 11: WP7 Performance

Using LayoutUpdatedprivate bool _onNavigatedToCalled = false; public Page() {

InitializeComponent(); LayoutUpdated += new EventHandler(Page_LayoutUpdated);

} protected override void OnNavigatedTo(NavigationEventArgs e) { _onNavigatedToCalled = true; } private void Page_LayoutUpdated(object sender, EventArgs e) {

if (_onNavigatedToCalled == true) { _onNavigatedToCalled = false; Dispatcher.BeginInvoke(() => { DoWork() } );

} }

Page 12: WP7 Performance

UI Performance Tips• Less is more• Minimize UI thread work• Leverage the GPU• Opacity vs. Visibility • BitmapCache• Never ever use OpacityMask• Use Manipulation Events over Mouse Events

Page 13: WP7 Performance

UI - Things to Avoid• Color Animation• Non-rectangular clips• Opacity masks• Popup• Converters• Watch for Callbacks that come back to UI

thread– e.g. WebClient, GeoCoordinateWatcher, etc.

Page 14: WP7 Performance

BitmapCacheCacheMode=“BitmapCache”

Useful for…• Render Transform

– Scale Transform– Rotate Transform– Translate Transform

• Change the opacity• Change the clipping

region

Danger Areas• Caches Bitmaps – not

Vectors!– You will lose fidelity– Try different

RenderAtScale

• Items frequently redrawn

• Non-rectangular clips

Page 15: WP7 Performance

Performance Counters• Composition Thread FPS• UI Thread FPS• Texture Memory Usage• Surface Counter• Intermediate Surface Counter• Screen Fill Rate Counter

Page 16: WP7 Performance

UI Performance

BitmapCacheFillRateTest

Page 17: WP7 Performance

ListBox Performance Tips• Don’t load so darn much data!• Simplify ListBox ItemTemplate• Avoid converters on bindings • Load images in the background (LowProfileImageLoader)

• Use Data Virtualization (e.g. LazyListBox)

• ListBox alternatives– StackPanel for short lists– LongListSelector for complex lists– LazyListBox + LowProfileImageLoader for alt. templates

Page 18: WP7 Performance

Control Alternatives• PerformanceProgressBar• LowProfileImageLoader• LongListSelector• LazyListBox• DeferredLoadListBox• DeferredLoadStackPanel • GroupingItemsControlConverter

Page 19: WP7 Performance

Custom ControlsPerformanceProgressBarLowProfileImageLoaderLazyLoadListBoxVirtualizingDataTest

Page 20: WP7 Performance

Data Performance Tips• Consider network latency• Consider impact of holding data in

memory• Parallelize data requests to save battery• Process data on background threads*• Use HttpWebRequest instead of WebClient

Page 21: WP7 Performance

Media• Use Jpeg over Png whenever possible• Use Images over Xaml whenever

possible• Limit image size to 2K x 2K• Set Build Action to Content• Encode media for optimal playback rate

and resolution

Page 22: WP7 Performance

Fast is not good enough!! • Perceived performance is important!

– Feedback on clicks – ProgressBar (use Jeff Wilcox) – Transitions across pages

• That said,– Don’t rely on our magic. – Use the counters and flags to verify. – Balance ‘feedback’ with real work ...

Page 23: WP7 Performance

Summary• How slow is slow?• Plan ahead for problem areas• Utilize the counters• Test, test, test – especially on a

device

Page 24: WP7 Performance

chriskoenig.net/WP7Resources

Page 25: WP7 Performance

Thanks to Jaime Rodriguez, Yochai Kiriati, 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.

Credits