Blograby

Resource Management and Performance

Like all mobile devices, Windows Phone 7 devices have limited processing, memory, and storage facilities compared to a desktop or laptop computer. It is important to take this into account when building applications that will run on Windows Phone 7.

The main areas of concern when designing mobile device applications are to manage device resource usage effectively and maximize performance on the device. Typically, maximizing performance involves optimizing memory utilization, maximizing use of the graphics processing unit (GPU), and more general issues, such as good programming practice. The following sections provide guidance on achieving these aims in your applications.

Minimize Device Resource Usage

reduce battery life. You should consider limiting use of these features when not necessary. For example, you should access the location service (which may initiate the built-in GPS) only when necessary, and turn it off when not required. Consider implementing options or power profiles in your applications that allow the user to minimize power use or turn off features of the device when not required.

Also consider how you can minimize the use of the network, Bluetooth, storage, video, sound, and background tasks. All of these require processor and memory resources, and they impose an additional load on the battery. For information about using the device capabilities, such as location services, and minimizing their impact on performance, see Appendix C, “Leveraging Device Capabilities.”

Apply Good Practice Programming Techniques

You must be aware of the work your application is doing and the use of resources within your code. Where possible, you should attempt to do the following:

Optimize Memory Usage

running on Windows Phone 7 if you carefully control use of memory and isolated storage. You must also be aware that garbage collection in Windows Phone 7 devices works differently than it does in desktop and server versions of the .NET Framework. In Windows Phone 7, the garbage collector runs only when memory usage exceeds a specified level, and it can interrupt execution—which can, therefore, affect performance.

Where possible, you should attempt to do the following:

Note: You can query the current memory availability and usage by your application using the DeviceExtendedProperties class in Windows Phone 7. For more information, see Appendix C of this book, “Leveraging Device Capabilities,” and “Device Information for Windows Phone” on MSDN (http://msdn.microsoft.com/en-us/library/ff941122(VS.92).aspx).

Maximize GPU Usage

Windows Phone 7 provides a background compositor thread that generates output for display and a relatively powerful GPU that maximizes performance for graphics and maintains an acceptable frame rate. However, you must take care to not negate this advantage through the use of code that cannot run on the GPU.

Where possible, you should attempt to do the following:

There are several modes you can enable when debugging. These are especially useful when maximizing graphics performance; they are automatically included in the code generated by the phone application template in Visual Studio. Graphics debug mode is set by the following properties of the Application.Current.Host.Settings class in the startup code in your App.xaml.cs file:

For more detailed information about the background compositor thread and maximizing performance on Windows Phone 7, see Creating High Performing Silverlight Applications for Windows Phone from the Microsoft Download Center (http://download.microsoft.com/download/B/2/7/B2748D7A-F368-4C33-B0F2-844CFE085193/SilverlightForWindowsPhonePerformance. zip). For more background information about performance optimization, see the video presentation, Silverlight Performance on Windows Phone, on the Mix 10 website (http://live.visitmix.com/MIX10/Sessions/CL60) and “WP7/SilverlightGraphics Performance” on andybeaulieu.com (http://www.andybeaulieu.
com/Home/tabid/67/EntryID/196/Default.aspx).

These and all links in this book are accessible from the book’s online bibliography. The URL to the bibliography can be found in the preface, in the final section, entitled, “Where to Go for More Information.”

 

Exit mobile version