Preface

You may already have an amazing iOS app, or be developing one. Everything looks great except for some kinks that prohibit users from giving the app that final fifth star or prevent you from releasing it.

Issues like a jitter when the user goes to the nth item in table view or the app hogging the network or consuming a lot battery are some of the visible symptoms that the user will be aware of. However, the problems lie somewhere deeper.

Tuning an app for performance is a never-ending task, especially with new app features, OS versions, third-party libraries, and device configurations. These are only some of the things that keep developers on their toes about app performance.

According to a study, about a quarter of users abandon an app if it does not load within 3 seconds, and about a third of users will tell others about their poor experience.

Users want apps that are fast, responsive, and do not hog resources. This book takes a look at various aspects that negatively impact use and outlines how you can tune your app for performance.

Who Should Read This Book

If you have been writing iOS apps and publishing them to the App Store, you have an implicit goal to make them better, faster, and more fluid—not to mention loved by your users. And if you are continuously looking for ways to achieve that goal, then this book is just for you.

You should already have working knowledge of Objective-C and iOS. This book is not about jump-starting with Objective-C or iOS, though the fundamentals will be revisited for completeness when necessary.

Why I Wrote This Book

iPhone OS 1 and iPhone 1 were launched in June 2007. During their early releases, developers were busy flushing out code and releasing apps for a wider audience. As the hardware, OS, networks, and overall ecosystem advanced over time—and as new user interface (UI) and engineering design patterns emerged—apps matured in functionality, stability, and performance.

More often than not, performance is an afterthought. And I can, to some degree, agree with that approach. After all, it is important to first get the functionality right, rather than worrying about performance. Thinking about optimizing early in the development lifecycle is more commonly referred to as premature optimization. But when poor performance hits, it hits hard.

The primary goal of this book is to show you how to write optimal code from an engineering perspective.

This book is not about theoretical computer science, data structures, and algorithms for faster execution of a task. You can find tons of literature on those topics. It covers best practices for implementing an app in such a manner that even in non-ideal conditions (low storage space, poor network, low battery, etc.), users still can use your app effectively and love using it. Generally, it will not be possible to optimize across all the parameters, but you’ll be able to achieve the best trade-off considering the available options.

Navigating This Book

This book is organized in five parts. Each part is comprised of one or more chapters that detail the theme of the particular part. Each chapter begins with a brief abstract outlining the topics that will be covered.

Part I provides an overview of how to measure performance. Chapter 1 discusses the aspects that we want to optimize and outlines the parameters we want to measure as part of tracking app performance.

Part II reviews the key optimizations that are core to any app. Chapter 2 addresses memory management. It describes the memory management model and object reference types. It also discusses best practices for design patterns that impact memory consumption, namely singleton and dependency injection.

Chapter 3 covers energy and techniques for minimizing consumption. Chapter 4 provides an overview of concurrent programming. It describes the various options available and gives a comparative analysis.

Part III covers performance optimization techniques specific to iOS app development. Chapter 5 provides in-depth coverage of the application lifecycle. It details how lifecycle events can be utilized to ensure resources are used effectively.

Chapter 6 reviews optimization techniques specifically for the user interface. Chapter 7 and Chapter 8 deal with networking and data sharing, respectively. Chapter 9 provides an in-depth review of security. It describes how enhanced security can slow down an app and discusses what can be done for an effective trade-off.

Part IV reviews the non-code aspects of performance. Chapter 10 covers testing, and performance testing in particular. It also discusses continuous integration and automation.

Chapter 11 provides an overview of the tools you can use to measure performance during development. Chapter 12 discusses instrumentation and analytics, and how it can be used to collect performance-related data from apps in production.

Part V focuses on iOS 9. Chapter 13 provides an outline of the changes in this release and how they impact the code you write from the perspective of performance.

Code snippets are provided throughout the book where applicable. Several of these snippets can be used either as is or with minimal modifications in your app. Other snippets may need to be further adapted to suit your app.

Each chapter also provides a set of best practices associated with the topic. It may not always be possible to follow all of the best practices in a single app. The decisions of which ones you want to trade off against others will be based on your app’s requirements.

Online Resources

This book refers to several online blogs, articles, tutorials, and other references. The links to those references are provided where applicable. Should you feel any reference has been missed out accidentally, feel free to contact the publisher or the author.

This book also references screenshots from several apps. The apps are copyright of their respective owners. The screenshots have been added for educational and illustrative purposes only.

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. It also highlights new code in program listings as compared to an earlier example that may have been shown.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Note

This icon signifies a general note.

Tip

This icon signifies a tip or suggestion.

Caution

This icon indicates a warning or a caution.

Using Code Examples

Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/gvaish/high-performance-ios-apps.

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 iOS Apps by Gaurav Vaish (O’Reilly). Copyright 2016 Gaurav Vaish, 978-1-491-91100-6.”

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

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://bit.ly/hp-ios-apps.

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

Even though it might seem so at times, nobody writes a book alone.

I am grateful to have worked closely with Daryl Low, Distinguished Architect at Yahoo!, in developing the monetization SDK from the ground up. He provided guidance on several sections in the book. It has always been fun and exciting to work with him on prototypical apps just to test performance extremes or identify the root cause of an error.

I would like to thank Walter Pezzini, who heads mobile DevOps engineering at Yahoo. He provided key insights on my understanding of continuous integration and a delivery pipeline, and what it takes to build a high-quality system.

As an author, it is easy to assume a few things to be known by the reader that may not always be the case. A big thanks goes to Chris Devers, Laura Savino, and Niklas Saers for their reviews, which identified areas that I needed to clarify. Thanks for also providing feedback that helped elevate overall content quality.

I would like to acknowledge Renu Chandel, my wife, for her continuous push to force me to complete this book. It would not have been finished if not for her. Thanks for all the coffee!

Last, but not the least, thanks to O’Reilly Media for publishing this book.

This book would not have been complete without collective efforts from all of you. Thanks, team.

Get High Performance iOS 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.