ebook img

High Performance Android Apps PDF

248 Pages·2015·10.67 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview High Performance Android Apps

H igh Performance Android Apps IMPROVE RATINGS WITH SPEED, e OPTIMIZATIONS, AND TESTING s a e e l R y r l a E D D I T E N E U & W A R Doug Sillars High Performance Android Apps Doug Sillars High Performance Android Apps by Doug Sillars Copyright © 2010 AT & T Services, Inc.. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Brian Anderson Indexer: FIX ME! Production Editor: FIX ME! Cover Designer: Karen Montgomery Copyeditor: FIX ME! Interior Designer: David Futato Proofreader: FIX ME! Illustrator: Rebecca Demarest January -4712: First Edition Revision History for the First Edition: 2014-11-03: Early release revision 1 2015-01-03: Early release revision 2 2015-03-03: Early release revision 3 2015-05-04: Early release revision 4 2015-07-20: Early release revision 5 See http://oreilly.com/catalog/errata.csp?isbn=9781491912485 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. !!FILL THIS IN!! and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-491-91248-5 [?] Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Introduction To Android Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Performance Matters to Your Users 2 E-Commerce and Performance 2 Beyond e-commerce Sales 3 Performance Infrastructure Savings 4 The Ultimate Performance Fail: Outages 4 Performance as a Rolling Outage 6 Consumer Reaction to Performance Bugs 7 Smartphone Battery Life - The Canary in the Coal Mine 8 Testing Your App For Performance Issues 9 Synthetic Testing 9 Real User Measurements (RUM) Testing 9 Conclusion 10 2. Building an Android Device Lab. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 What Devices Are your Customers Using? 11 Device Spec Breakdown 12 Screen 12 SDK Version 13 CPU/Memory and Storage 13 What Networks are Your Customers Using? 13 Your Device is Not Your Customer’s Device 13 Testing 15 Building Your Device Lab 15 You Want $X,000 for Devices? 16 So What Devices Should I Pick? 17 Popular Yesterday 18 iii Popular Today 18 Popular Tomorrow 18 Beyond Phones 19 Android Wear 19 Android Open Source Project Devices 19 Amazon 20 Other Android phones/tablets 20 Other 20 Remote Device Testing 21 Open Device Labs 21 Other Considerations 22 Conclusion 22 3. Hardware Performance and Battery Life. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Android Hardware Features 25 Less is More 26 What Causes Battery Drain 27 Android Power Profile 27 Screen 29 Radios 30 CPU 31 Additional Sensors 31 Get To Sleep! 32 Wakelocks and Alarms 33 Doze Framework 34 Basic Battery Drain Analysis 35 App Specific Battery Drain 38 Coupling Battery Data with Data Usage 41 App Standby 44 Advanced Battery Monitoring 44 BatteryStats 45 Battery Historian 49 Battery Historian 2.0 59 JobScheduler 62 Conclusion 67 4. Screen and UI Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 UI Performance Benchmarks 69 Jank 70 UI and Rendering Performance Updates in Android 70 Building Views 71 Hierarchy Viewer 73 iv | Table of Contents Asset Reduction 86 Overdrawing the Screen 86 Testing Overdraw 87 Overdraw in Hierarchy Viewer 89 Overdraw and KitKat (Overdraw Avoidance) 92 Analyzing For Jank (Profiling GPU Render) 93 GPU Rendering in Android M 95 Beyond Jank (Skipped Frames) 97 SysTrace 97 Systrace Screen Painting 100 Systrace and CPU Usage Blocking Render 107 Systrace Update - I/O 2015 109 Vendor Specific Tools 112 Perceived Performance 112 Spinners: the Good and the Bad 112 Animations to Mask Load Times 113 The White Lie of Instant Updates 113 Tips To Improve Perceived Performance 114 Conclusion 114 5. Memory Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Android Memory: How it Works 115 Shared vs. Private Memory 116 Dirty vs. Clean Memory 116 Memory Cleanup (Garbage Collection) 117 Figuring Out How Much Memory Your App Uses 120 Procstats 125 Android Memory Warnings 129 Memory Management/Leaks in Java 130 Tools for Tracking Memory Leaks 130 Heap Dump 130 Allocation Tracker 133 Adding a Memory Leak 134 Deeper Heap Analysis: MAT and Leak Canary 137 MAT Eclipse Memory Analyzer Tool 137 LeakCanary 144 Memory Summary 147 6. CPU and CPU Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Measuring CPU Usage 150 Systrace for CPU Analysis 152 Traceview (legacy Monitor DDMS tool) 155 Table of Contents | v Traceview (Android Studio) 158 Other Profiling Tools 162 Conclusion 164 7. Network Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Wi-Fi vs. Cellular Radios 166 Wi-Fi 166 Cellular 166 RRC State Machine 167 Testing Tools 171 Wireshark 172 Fiddler 173 MITMProxy 175 AT&T Application Resource Optimizer 176 Hybrid Apps and WebPageTest.org 180 Network Optimizations for Android 180 File Optimizations 181 Text File Minification (Souders: Minify Javascript) 182 Images 183 File Caching 185 Beyond Files 188 Grouping Connections 188 Detecting Radio Usage in Your App 190 All Good Things Must Come to An End: Closing Connections 192 Regular Repeated Pings 194 Security in Networking (HTTP vs. HTTPS) 195 Worldwide Cellular Coverage 195 CDNs 197 Testing Your Application On Slow Networks 197 Emulating Slow Networks Without Breaking the Bank 198 Building Network Aware Applications 200 Accounting For Latency 203 Last Mile Latency 204 “Other” Radios 204 GPS 204 Bluetooth 204 Conclusion 207 8. Real User Measurements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Enabling RUM tools 210 RUM Analytics - Sample App 211 Crashing 213 vi | Table of Contents Examining A Crashalytics Crash Report 214 Usage 220 Real Time Information 225 Big Data to the Rescue? 225 RUM SDK Performance 225 Conclusion 228 A. Organizational Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Table of Contents | vii Preface You are building an Android application (or you already have.) Despite this, are you not totally happy with your apps performance? (why else did you pick up this book?) Uncovering mobile performance issues is a job that is never complete. In my research, I found that 98% of apps tested had potential performance improvements. The goal of this book is to help understand the pitfalls of mobile performance, expose some of the tools to test for issues so that you can catch any major performance issues in your mobile application before it impacts your customers. Studies have shown that customers expect mobile applications to load quickly, to rapidly respond to user interactions, and be smooth and pleasing to the eye. As application get faster, user engagement and revenues increase. Mobile applications built without an eye on performance are uninstalled at the same rate as those that crash. Apps that ineffi‐ ciently use resources cause unnecessary battery drain. The #1 complaint to carriers and device manufacturers is battery life. I have spoken to thousands of developers about Android app performance over the last few years, and few developers were aware of the tools available for solving the issues they were having. The consensus is clear: mobile applications that are fast and run smoothly are used more often and make more money for the developers. With that information, it is surprising that more developers are not using the tools that are available to diagnose and pinpoint performance issues in their apps. By focusing on how performance improvements affect the user experience, you can quickly identify the Return on Investment that your per‐ formance work has made on your mobile application. Who Should Read This Book This book covers a wide range of topics centering around Android Performance. Any‐ one associated with mobile development will appreciate the research around application performance. Developers of mobile applications will find the arguments and issues ix

Description:
I have spoken to thousands of developers about Android app performance We'll walk through the steps to optimize the UI by making the from publishers like O'Reilly Media, Prentice Hall Professional, Addison-Wesley Pro‐ . (a study in 2012 found that slow apps caused 4% of users to throw their.
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.