Weitere ähnliche Inhalte Ähnlich wie Windows Phone app Performance and Memory Consumption Tuning by Jevgeni Tsaikin (20) Kürzlich hochgeladen (20) Windows Phone app Performance and Memory Consumption Tuning by Jevgeni Tsaikin7. • loading, parsing, fetching data
Background Threads • networking
8. • Parse and create objects from XAML
• Draw all visuals the first time they are drawn
UI Thread • Process per-frame callbacks and execute
other user code
• Bindings
• loading, parsing, fetching data
Background Threads • networking
9. • Storyboard-driven animations (including
ScaleTransform, TranslateTransform,
RotateTransform, PlaneProjection)
Composition Thread NB! Scale transforms must be less than 50 percent
of the original size
• Clip, Opacity
• Back-buffer
• Parse and create objects from XAML.
• Draw all visuals the first time they are drawn.
UI Thread • Process per-frame callbacks and execute
other user code
• Bindings
• loading, parsing, fetching data
Background Threads • networking
Hinweis der Redaktion Skype for Windows Phone 10/14/12 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group We all want to create applications that run snappy and fast and performance optimization helps us to achieve this goal. Those applications provide users with… 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group There is a set of technical certification requirements from the Marketplace dedicated to performance and resource management. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group What are we going to discuss today? I will begin with explaining to you the basics of threading model used on Windows Phone platform. Then I will introduce you to a set of tools we can use to profile app performance and memory usage. After that we are going to discuss more specific things such as speeding up the startup of an application, speeding up the navigation between pages. Then I give some general performance considerations. And at the end we will discuss virtualization and how to fix the memory leaks. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Most of our applications deal with large amount of data and to provide user with a smoother UX we need to delegate most of our data operations to background thread. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group UI Thread is the main thread of our application which deals with parsing and creating objects from XAML, drawing all visual content for the first time, process per-frame callbacks and execute user code. Also it takes care of the bindings. Important thing is that thread is executed on the CPU. If this thread is very busy user may experience glitches and lags in application. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Composition thread mostly handles storyboard-driven animations such as ScaleTransform, TranslateTransform, RomateTransform and others. One limitation for ScaleTransform is that the scale should not be over 50 percent of original size. It also handles such properties as Clip and Opacity. Another important part is back-buffer… Composition Thread is mostly execute on GPU… +Direct Manipulation Thread to handle scrolling for lists. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group The main idea behind performance and CPU usage optimization is to keep as much activity off of the UI thread as possible and pass the activities down to Composition Thread and Background Threads. Then the application will run much smoother, without any glitches or lags. 10/14/12 Here is a list of tools that I use in my daily developer life. Those tools are… 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group WP Perf Analysis tools helps us to identify…, but the main purpose for this tool is to measure memory and CPU usage. Green – UI Thread (less than 50%), Purple – Composition+Background, Grey – system, White – available CPU 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Composition (Render) Thread Frame Rate (FPS) The rate at which the screen is updated. User Interface Thread Frame Rate (FPS) The rate at which the UI thread is running. Texture Memory Usage The video memory and system memory copies of textures being used in the application. Surface Counter The number of explicit surfaces being passed to the GPU for processing. Intermediate Surface Counter The number of implicit surfaces generated as a result of cached surfaces. Screen Fill Rate Counter The number of pixels being painted per frame in terms of screens. A value of 1 represents 480 x 800 pixels. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Some of those values have recommended thresholds. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group EnableRedrawRegions helps developers to identify the areas that are being redrawn each frame. Usually some of the areas are redrawn without developer intention or by mistake which also steal some of CPU/GPU resourses. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Let’s now talk about how can we speed up the startup. It is important because startup is the first time user meets the application and develop first impression, so it needs to be really fast. What can we do to achieve that goal? … 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Let’s now talk about how can we speed up the startup. It is important because startup is the first time user meets the application and develop first impression, so it needs to be really fast. What can we do to achieve that goal? … 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Another important area for optimization is the navigation between pages. It also needs to be optimized to provide user is with lag-free page transition. What can we do to optimize that? 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group One of the major differences between JPG and PNG formats is that JPG decoder is much faster than the PNG one. Also I would highly recommend to avoid image scaling in your applications to save some CPU and also you have to limit the image size to 2000x2000 pixels, because larger images will be sampled at a lower resolution. Which again leads to a CPU loss. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Another important thing is to use static visuals such as images instead of XAML, because XAML needs to be reinterpreted on UI Thread, which usually takes more time than just displaying a static image. Finally, since Mango release we can now use CreateOptions to delegate the image decoding to a background thread instead of blocking the UI thread. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group How can we show and hide UI elements within our applications? There are two main ways to do that in Windows Phone environment: it is by using Visibility property or Opacity property. Then Visibility is set to collapsed then Silverlight does not hold any visual data for the element, but when we set the Visibility back to Visible the object is redrawn completely. While the UI element with Opacity set to 0 still stays in memory, but doesn’t require the object to be redrawn. It is a trade-off between the CPU and Memory usage. From my personal experience I would recommend to use Opacity combined with Bitmap Caching to improve the performance. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group When it comes to displaying lists we can follow two basic approaches. First of all we can use StackPanel and secondly we can use VirtualizingStackPanel. What’s the difference between them? Pretty simple, StackPanel keeps all the elements in memory while VirtualizingStackPanel keeps only those items that fit into visible viewport plus two viewports in a buffer and all the rest is loaded on demand. One of the best implementations of VirtualizingStackPanel is the ListBox which is virtualized by default. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group Limited to hardware, Less Memory, Less processing power. In some cases smooth UX is more important than fancy animations and extremely rich content. Also test on real devices, because emulator doesn’t provide you with accurate measurements. 10/14/12 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Microsoft Consumer Channels and Central Marketing Group LITHUANIA 10/14/12 11:29 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. LATVIA 10/14/12 11:29 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. ESTONIA 10/14/12 11:29 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.