Preface

You are building an Android application (or you already have). Despite this, you are not totally happy with your app’s 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 room for potential performance improvements. This book will cover the pitfalls of mobile performance and introduce you to some of the tools to test for issues. My goal is to help you acquire the skills necessary for catching any major performance issues in your mobile app before they impact your customers.

Studies have shown that customers expect mobile apps to load quickly, rapidly respond to user interactions, and be smooth and pleasing to the eye. As apps get faster, user engagement and revenue increase. Mobile apps 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 number one complaint carriers and device manufacturers hear from customers concerns 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 experience.

The consensus is clear: mobile apps that are fast and run smoothly are used more often and make more money for 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 app.

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 app performance. Developers of non-Android mobile apps 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 in which developers share tips on how to make the Web fast. Steve Souders wrote High Performance Web Sites in 2007 (O’Reilly), and the topic is covered in books, blogs, and conferences.

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 OSs have matured, customers are realizing that mobile apps have a role in the performance of their phones.

There are many great tools for measuring Android app performance, but until now, there hasn’t been a guide listing 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 app get faster while not killing your customers’ batteries.

Navigating This Book

When it comes to studying application performance, I have chosen to look at how your app’s code affects different aspects of the Android device. We’ll start at a high level: performance and the Android ecosystem, and then look at how your app’s behavior affects the screen, CPU, network stack, etc.

Chapter 1, Introduction to Android Performance

This chapter introduces the topic of mobile app performance. We’ll run the numbers to show how crucial performance is to your app. I’ll highlight many of the challenges, but also the effects of poor performance in the marketplace. These are the stats you can use to convince your management that putting effort into speeding up your apps is time well spent. The data presented here generally holds for all mobile platforms and devices.

Chapter 2, Building an Android Device Lab

Here we’ll cover testing. Android is a huge ecosystem with tens of thousands of devices, each with different UIs, screens, processors, and OS versions (to name just a few considerations). I’ll 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, Hardware Performance and Battery Life

Next, we’ll discuss the battery, including what causes drain and how much drain. In addition, this chapter covers how your customers may discover battery issues in your app, and developer tools to isolate battery issues. We’ll also look at the new JobScheduler API (released in Lollipop), which abstracts application wakeups to the OS.

Chapter 4, Screen and UI Performance

Screen performance accounts for the largest power drain on users’ phones, and the screen serves as the primary interface to your app—this is where slow apps show jank (skipped frames) and slow rendering. This chapter walks 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.

Chapter 5 and Chapter 6, Memory Performance and CPU and CPU Performance

These chapters look at memory and CPU issues such as garbage collection, memory leaks, and how they affect the performance of your app. You’ll learn how to dig into your app to discover potential issues by using testing tools such as Procstats, Memory Analysis Tool (MAT), and Traceview.

Chapter 7, Network Performance

Here we’ll look at the network performance of your app. This is where I got started in mobile performance optimization, and we’ll look into the black box of how your app is communicating with your servers and how we might enhance these communications. We’ll also look at how to test the performance of your app on slower networks (as much of the developing world will be on 2G and 3G for decades to come).

Chapter 8, Real User Measurements

Finally, we’ll discuss how to use real user-monitoring 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 A, Organizational Performance

Here we’ll cover organizational performance, including how to get buy-in to build 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.

Using Code Examples

There are several sample apps in the book. The sample code can be found at https://github.com/dougsillars/HighPerformanceAndroidApps.

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 you’re 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 O’Reilly 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 product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “High Performance Android Apps by Doug Sillars (O’Reilly). Copyright 2015 AT&T Services, Inc., 978-1-491-91251-5.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

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.

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals.

Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://www.oreilly.com/catalog/0636920035053.do.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

To everyone at AT&T—my boss, Ed (and his boss, Nadine), and everyone in the AT&T Developer Program (Ed S., Jeana, and Carolyn). I would like to especially shout out to the ARO team members—Jen, Bill, Lucinda, Tiffany Pete, Savitha, John, and Rod (and of course all the devs!)—who work every day to share performance tools with the developer community. My colleagues past and present in AT&T Labs: Feng, Shubho, Oliver—thank you for coming up with the idea of ARO, and getting us involved in app performance.

A big thank you to everyone who read the early iterations of the book—your comments, tips, and suggestions were invaluable. To my technical reviewers and editors—thank you for all the great feedback and suggestions. You have helped make the book stronger!

Last, but most importantly, I would like to thank my wife and three children for their patience through the late nights (and the subsequent grumpy mornings) as this book grew from an idea to final form. I couldn’t have done it without you guys, and I love you so very much. 1437313.

It’s funny—I have a PhD studying chemical reaction mechanics and kinetics (how reactions work, and how to make them faster). Who knew that it would translate into a career studying mobile app mechanisms, optimizations, and kinetics?

Get High Performance Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.