High Performance Android Apps
Doug Sillars
Beijing Cambridge Farnham Kln Sebastopol Tokyo
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 inefficiently 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 performance work has made on your mobile application.
Who Should Read This Book
This book covers a wide range of topics centering around Android Performance. Anyone associated with mobile development will appreciate the research around application performance. Developers of mobile applications will find the arguments and issues around app performance useful, but the tools used to isolate the issues are Android specific.
Testers will find the tutorials of tools used to test Android performance useful as well.
Why I Wrote This Book
There is a large and burgeoning field of web performance where developers share tips on how to make the web fast. Steve Souders wrote High Performance Web Sites in 2007, and the topic is covered in books, blogs, conferences, etc.
Until recently, there has been very little focus on mobile app performance. Slow apps were blamed on the OS or the cellular network. Poor battery life was blamed on device hardware. As phones have gotten faster and the OSes have matured, customers are realizing that mobile apps have a role in the performance of their phone.
There are many great tools for measuring Android app performance, but until now - no guide that lists them all in one place. By bringing in tools from Google, Qualcomm, AT&T and others I hope this book will take some of the mystery out of Android performance testing, and help your application get faster while not killing your customers battery.
Navigating This Book
- Chapter 1 is an introduction to mobile app performance. Well run the numbers to show how crucial performance is to your application. Ill highlight many of the challenges, but also the effects of poor performance in the marketplace. These are the stats that you can use to convince your management that spending time speeding up your applications is time well spent. tTe data presented here generally holds for all mobile platforms and devices.
- Chapter 2 covers testing. Android is a huge ecosystem with tens of thousands of devices with different UIs, screens, processors OS versions etc. Ill walk through some of the ideas to help your testing cover as many device types as possible without breaking the bank (too much).
- Chapter 3 is all about the battery. What causes drain, and by how much. How your customers may discover battery issues in your app, and developer tools to isolate battery issues. I also cover the new JobScheduler API (released in Lollipop) that abstracts application wakeups to the OS.
- Chapter 4 Screen Perf. Being the largest power drain on your phone, and the primary interface to your app - this is where slow apps show jank (skipped frames) and slow rendering. Well walk through the steps to optimize the UI by making the hierarchy flatter, and how to test for jank and jitter in your app using tools like Systrace.
- Chapters 5 and 6 look at Memory and CPU issues like garbage collection and memory leaks and how they affect the performance of your app. Testing with tools like Procstats, MAT and TraceView - youll learn to dig into your app to discover potential issues.
- Chapter 7 looks at the network performance of your app. This is where I got started in mobile perf, and well look into the black box of how your app is communicating with your servers and how we might optimize these communications. Well also look at how to test the performance of your application on slower networks (since much of the developing world will be on 2G and 3G for decades to come.)
- Chapter 8 Using Real User Measurements and analytics data to ensure that every device is getting the optimal user experience. As shown in Chapter 2 - there is no way to test every Android device out there, but it is up to you to monitor the performance of your app on your customers devices.
- Appendix Covers organizational performance. How to get buy-in to building performant apps. By sharing the research, success stories, and proofs of concept, you can show your company that placing performance as a goal for the whole organization will improve the bottom line.
Online Resources
There are several sample applications in the book. The sample code can be found at https://github.com/dougsillars/HighPerformanceAndroidApps.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/title_title.
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
Next page