High-Performance Windows Store Apps Foreword by Eric Lippert, C# Analysis Architect, Coverity Brian Rasmussen PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2014 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number: 2014935300 ISBN: 978-0-7356-8263-4 Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at [email protected]. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Devon Musgrave Developmental Editor: Devon Musgrave Project Editor: Devon Musgrave Editorial Production: Christian Holdener, S4Carlisle Publishing Services Technical Reviewer: Marc Young Copyeditor: Roger LeBlanc Indexer: Jean Skipp Cover: Twist Creative • Seattle and Joel Panchot To Kirsten for all your love and support. Thank you for going on this adventure with me. I love you! To Asbjørn and Janus for showing me a new and fantastic view of the world. I love you! Contents at a Glance Introduction CHAPTER 1 Setting the stage CHAPTER 2 Platform overview CHAPTER 3 Designing for performance CHAPTER 4 Instrumentation CHAPTER 5 Performance testing CHAPTER 6 Investigating performance issues CHAPTER 7 Wrap-up Index Table of Contents Foreword Introduction Chapter 1 Setting the stage Why is app performance so hard to optimize? A typical project Fast, fluid, and efficient Fast Fluid Efficient Working with performance in mind Performance tools Visual Studio 2013 Windows Performance Toolkit PerfView Event Tracing for Windows XAML framework Getting started with Windows Performance Toolkit Installing WPT on Windows 8.1 Installing WPT on Windows RT Introduction to Windows Performance Recorder Recording performance data Introduction to Windows Performance Analyzer Summary Chapter 2 Platform overview Anatomy of an app Process start Reading and parsing XAML Layout Binding All abstractions come with a price tag Windows platform and tools The Windows Runtime Metadata Projections Process lifetime management Memory Resource management XAML Less is more Virtualization Images Binding XAML threads Animations Overdraw Asynchronous code DirectX The Common Language Runtime Assemblies Just-in-time compilation Automatic memory management Threads and tasks Your app The right tools for the task Blocking the UI thread Overloading the UI thread Too much data Heavy-duty serialization Summary Chapter 3 Designing for performance Less is more Proof of concept Design challenges Login Live content Prioritize your content, and make sure it is available Use caching to reduce downloads Use ContentPrefetcher to load data in advance Asynchronous I/O Extended splash screen Handling a lot of content Prioritize your content Partition content to reduce workload Cache information to improve transitions Handling media Playing video Displaying images Playing audio Releasing resources Summary Chapter 4 Instrumentation Event Tracing for Windows Overview of event tracing Manifests WinRT instrumentation Using WinRT instrumentation Recording events with WPR Analyzing performance Improving performance EventSource-based instrumentation Create a custom EventSource Instrument your code Create a recording profile for your EventSource Using your custom event source Troubleshooting Summary Chapter 5 Performance testing Why are performance tests special? What to test What hardware to test on Handling signal-to-noise ratio Cold vs. warm tests Repeatable tests Troubleshooting Addressing regressions Windows App Certification Kit performance tests Performance tests Building a performance test environment Coded UI tests Collecting performance test data Test results Improvements Manual testing Collecting additional performance data Dogfooding Telemetry Summary Chapter 6 Investigating performance issues Windows Performance Analyzer revisited Overview of WPA Loading symbols Understanding graphs in WPA Working with performance data in WPA Methodology Sample investigations Slow startup Slow page navigation Sluggish panning performance Summary Chapter 7 Wrap-up Applying the advice of the book Additional resources Videos Online resources Additional tools Books In closing Index What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey