SlideShare une entreprise Scribd logo
1  sur  25
iOS App Performance 
Things to Take Care 
Gurpreet Singh Sachdeva 
Engineering Manager @ Yahoo
Who should attend this session? 
• If you are developing or planning to develop 
iOS apps and looking for tips to make your 
apps fast then you are right place. 
• Pre-requisite: Basic Objective-C knowledge
Why performance is important? 
• Faster apps provide a better user experience 
• Users expect high performance 
• If your app is slow or unresponsive it is bound 
to get bad reviews and loose user base. 
• Remember, mobile devices have less RAM.
Performance Tips 
• Use ARC 
• In addition to helping you avoid memory leaks, ARC can 
also improve your performance, by making sure that 
objects are de-allocated as soon as they are no longer 
needed. 
• These days, you should always use ARC in your projects!
Performance Tips 
• Don’t block the main thread 
• You should never do any heavy lifting on the main 
thread. Remember, UIKit does all of its work on the 
main thread, such as drawing, managing touches, and 
responding to input. 
• Most cases of blocking the main thread occur when your 
app is performing an I/O operation which involves any 
task that needs to read or write from an external 
source, such as the disk or the network. 
• You can perform network tasks asynchronously by using 
this method on NSURLConnection
Performance Tips 
• Use a reuseIdentifier where appropriate 
• A table view’s data source should generally reuse 
UITableViewCell objects when it assigns cells to rows. 
• Otherwise, table view will configure new cell each time 
a row is displayed. This is an expensive operation and 
will affect the scrolling performance of your app 
• To use reuseIdentifiers, call this method from your data 
source object when asked to provide a new cell for the 
table view: 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Performance Tips 
• Avoid fat XIBs 
• If you are still using XIB files for some reason (may be for 
supporting pre iOS 5 devices) then make them as 
uncomplicated as possible. 
• Note that when you load a XIB into memory, all of its 
contents are loaded into memory, including any images. 
• If you have a view you’re not using immediately, then you’re 
wasting precious memory. 
• It’s worth noting that this won’t happen with storyboards, 
since a storyboard will only instantiate a view controller when 
it’s needed.
Performance Tips 
• Size images to Image Views 
• Scaling images on the fly can be expensive, especially if 
your UIImageView is embedded in a UIScrollView. 
• If the image is downloaded from a remote service, 
sometimes you don’t have control over the size, or you 
might not be able to scale it on the server prior to 
downloading.
Performance Tips 
• Choose the correct Collection 
• Learning to use the most appropriate class or object for 
the task at hand is fundamental to writing efficient 
code. This is especially true when dealing with 
collections. 
• There is a document on Apple’s Developer Library that 
explains in detail the differences between the available 
classes, as well as which situations suit each class. It’s a 
must read document for anyone looking to work with 
collections.
Performance Tips 
• Enable GZIP compression 
• Speed up the download of network-based resources by 
enabling GZIP compression on both your server and on 
your client. 
• The good news is that iOS already supports GZIP 
compression by default if you’re using 
NSURLConnection, or a framework built on top of it such 
as AFNetworking. 
• There is a great article about GZIP compression which 
explains how to enable it on your Apache or IIS server.
Performance Tips 
• Reuse and lazy Load Views 
• Create your views as you need them. 
• More views means more drawing; which ultimately 
means more CPU and memory overhead. This is 
especially true if your app embeds many views inside of 
a UIScrollView.
Performance Tips 
• Cache what matters 
• Cache things that are unlikely to change, but are 
accessed frequently. 
• What can you cache? 
• Some candidates for caching are remote server responses, 
images. 
• NSURLConnection already caches resources on disk or in 
memory according to the HTTP headers it processes.
Performance Tips 
• Handle memory warnings 
• iOS notifies all running apps when system memory is 
running low. 
• UIKit provides several ways to receive these low-memory 
warnings, including the following: 
• Implement the applicationDidReceiveMemoryWarning: method of your 
app delegate. 
• Override didReceiveMemoryWarning in your custom UIViewController 
subclass. 
• Register to receive the 
UIApplicationDidReceiveMemoryWarningNotification notification. 
• Upon receiving any of these warnings, free up any unnecessary 
memory. 
• Purge unused data structures, release any images that are not 
currently on-screen.
Performance Tips 
• Reuse expensive Objects 
• Some objects are very slow to initialize — 
NSDateFormatter and NSCalendar are two examples. 
• To avoid performance bottlenecks when working with 
these objects, try to reuse these objects if at all possible. 
• You can do this by either adding a property to your class or 
using static
Performance Tips 
• Optimize Your Table Views 
• Tips for optimizing Table Views 
• Reuse cells by setting the correct reuseIdentifier. 
• Make as many views opaque as possible, including the cell 
itself. 
• Avoid gradients, image scaling. 
• If the cell shows content that comes from the web, be sure to 
make those calls asynchronously and cache the responses. 
• Reduce the number of subviews. 
• Do as little work as possible in cellForRowAtIndexPath:. If you 
need to do some work, do it only once and cache the results. 
• Use the appropriate data structure to hold the information you 
need. Different structures have different costs for different 
operations.
Performance Tips 
• Speed up launch time 
• Launching your app quickly is very important, especially 
when the user launches for the first time. First 
impressions mean a lot for an app! 
• Ensure your app starts as quickly as possible is to 
perform asynchronous tasks. 
• You need to strike a balance between what to fetch before app 
launch and what to fetch once the app is launched. 
• Try to avoid fat XIBs, since they’re loaded on the main 
thread. But recall that storyboards don’t have this 
problem — so use them if you can!
Performance Tips 
• Cache Images (when?) 
• There are two common ways to load a UIImage from an 
app bundle. 
• Using imageNamed and second using 
imageWithContentsOfFile. 
• imageNamed has the advantage of caching the image as it’s loaded. 
• Alternately, imageWithContentsOfFile simply loads the image with no 
caching. 
• When would you use one over the other? 
• If you’re loading a large image that will be used only once, 
there’s no need to cache the image. 
• However, imageNamed is a much better choice for images that 
you’re going to be reusing in your app.
Performance Tips 
• Reduce battery consumption 
• Optimize use of the following features: 
• The CPU 
• Wi-Fi, Bluetooth, and baseband (EDGE, 3G) radios 
• The Core Location framework 
• The accelerometers 
• The disk 
• Consider the following guidelines: 
• Avoid doing work that requires polling. 
• Avoid accessing the disk too frequently. 
• Do not draw to the screen faster than is needed. 
• Connect to external network servers only when needed, and do 
not poll those servers. 
• Disable location updates as soon as you can.
Performance Tips 
• Reduce App’s memory footprint 
• Actions to take 
• Eliminate memory leaks. 
• Make resource files as small as possible. 
• Use Core Data or SQLite for large data sets. 
• Load resources lazily.
Performance Tips 
• Use NSLog as sparingly as possible in production 
• Messages written using NSLog are presented in the 
debugger console and even to the device's console log 
in production. 
• NSLog() takes a non-negligible amount of time. 
• The following are commonly used log definitions that 
are used to selectively perform NSLog() in 
debug/production: 
#ifdef DEBUG 
// Only log when attached to the debugger 
# define DLog(...) NSLog(__VA_ARGS__) 
#else 
# define DLog(...) /* */ 
#endif 
// Always log, even in production 
#define ALog(...) NSLog(__VA_ARGS__)
Performance Tips 
• Be Lazy 
• Defer memory allocations until you actually need the 
memory. 
• Defer reading the contents of a file until you actually 
need the information.
Performance Tips 
• Take Advantage of Perceived Performance 
• The perception of performance is just as effective as 
actual performance in many cases. 
• Many program tasks can be performed in the 
background, using a dispatch queue, or at idle time. 
• Doing this keeps the application’s main thread free to handle 
user interactions and makes the program interface feel more 
responsive to the user. 
• If your program needs to scan a number of files or perform 
lengthy calculations, do so using a dispatch queue. 
• There is a good document available on apple’s site for 
Concurrency Programing
Analyzing the performance 
• Using apple tools for analyzing performance 
• https 
://developer.apple.com/library/ios/documentation/Performance/ 
Conceptual/PerformanceOverview/PerformanceTools/Performanc 
eTools.html#//apple_ref/doc/uid/TP40001410-CH205-BCIIHAAJ
References 
Marcelo Fabri - 25 iOS App Performance Tips & Tricks. Retrieved from 
http://www.raywenderlich.com/31166/25-ios-app-performance-tips-tricks
iOS App performance - Things to take care

Contenu connexe

Tendances

Presentation on java (8)
Presentation on java (8)Presentation on java (8)
Presentation on java (8)Shwetakant1
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Edureka!
 
Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Ippon
 
Java EE no ambiente corporativo: primeiros passos WebLogic 12c
Java EE no ambiente corporativo: primeiros passos WebLogic 12cJava EE no ambiente corporativo: primeiros passos WebLogic 12c
Java EE no ambiente corporativo: primeiros passos WebLogic 12cBruno Borges
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEdureka!
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Duckademy IT courses
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Edureka!
 
Java programming(unit 1)
Java programming(unit 1)Java programming(unit 1)
Java programming(unit 1)SURBHI SAROHA
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 

Tendances (20)

Presentation on java (8)
Presentation on java (8)Presentation on java (8)
Presentation on java (8)
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
 
Java seminar
Java seminarJava seminar
Java seminar
 
Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon Formation Gratuite Total Tests par les experts Java Ippon
Formation Gratuite Total Tests par les experts Java Ippon
 
Ruby programming
Ruby programmingRuby programming
Ruby programming
 
Java EE no ambiente corporativo: primeiros passos WebLogic 12c
Java EE no ambiente corporativo: primeiros passos WebLogic 12cJava EE no ambiente corporativo: primeiros passos WebLogic 12c
Java EE no ambiente corporativo: primeiros passos WebLogic 12c
 
Enumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | EdurekaEnumeration in Java Explained | Java Tutorial | Edureka
Enumeration in Java Explained | Java Tutorial | Edureka
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java modules
Java modulesJava modules
Java modules
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...
 
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
Java Tutorial For Beginners - Step By Step | Java Basics | Java Certification...
 
Java programming(unit 1)
Java programming(unit 1)Java programming(unit 1)
Java programming(unit 1)
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Java Class Loader
Java Class LoaderJava Class Loader
Java Class Loader
 
Java collection
Java collectionJava collection
Java collection
 

Similaire à iOS App performance - Things to take care

Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Jess Coburn
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best PracticesJean-Luc David
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara AnjargolianHakka Labs
 
Google app development
Google app developmentGoogle app development
Google app developmentAurel Medvegy
 
Google app developers
Google app developersGoogle app developers
Google app developersAurel Medvegy
 
Web software development
Web software developmentWeb software development
Web software developmentAurel Medvegy
 
Google app developer
Google app developerGoogle app developer
Google app developerAurel Medvegy
 
Google apps development
Google apps developmentGoogle apps development
Google apps developmentAurel Medvegy
 
Cloud service provider
Cloud service providerCloud service provider
Cloud service providerAurel Medvegy
 
Google app engine developer
Google app engine developerGoogle app engine developer
Google app engine developerAurel Medvegy
 
Cloud computing providers
Cloud computing providersCloud computing providers
Cloud computing providersAurel Medvegy
 

Similaire à iOS App performance - Things to take care (20)

Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
iOS Coding Best Practices
iOS Coding Best PracticesiOS Coding Best Practices
iOS Coding Best Practices
 
Appengine json
Appengine jsonAppengine json
Appengine json
 
Performant Django - Ara Anjargolian
Performant Django - Ara AnjargolianPerformant Django - Ara Anjargolian
Performant Django - Ara Anjargolian
 
Google app development
Google app developmentGoogle app development
Google app development
 
Google app developers
Google app developersGoogle app developers
Google app developers
 
Google development
Google developmentGoogle development
Google development
 
Google app
Google appGoogle app
Google app
 
Web software development
Web software developmentWeb software development
Web software development
 
Google app developer
Google app developerGoogle app developer
Google app developer
 
Google web tools
Google web toolsGoogle web tools
Google web tools
 
Google apps development
Google apps developmentGoogle apps development
Google apps development
 
Google app pricing
Google app pricingGoogle app pricing
Google app pricing
 
Cloud service provider
Cloud service providerCloud service provider
Cloud service provider
 
Google apps
Google appsGoogle apps
Google apps
 
App engine domain
App engine domainApp engine domain
App engine domain
 
Google app engine developer
Google app engine developerGoogle app engine developer
Google app engine developer
 
Cloud computing providers
Cloud computing providersCloud computing providers
Cloud computing providers
 
Google app software
Google app softwareGoogle app software
Google app software
 

Plus de Gurpreet Singh Sachdeva (6)

Firefox addons
Firefox addonsFirefox addons
Firefox addons
 
Introduction to Greasemonkey
Introduction to GreasemonkeyIntroduction to Greasemonkey
Introduction to Greasemonkey
 
iOS training (advanced)
iOS training (advanced)iOS training (advanced)
iOS training (advanced)
 
iOS training (intermediate)
iOS training (intermediate)iOS training (intermediate)
iOS training (intermediate)
 
iOS training (basic)
iOS training (basic)iOS training (basic)
iOS training (basic)
 
Introduction to Data Warehousing
Introduction to Data WarehousingIntroduction to Data Warehousing
Introduction to Data Warehousing
 

Dernier

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Dernier (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

iOS App performance - Things to take care

  • 1. iOS App Performance Things to Take Care Gurpreet Singh Sachdeva Engineering Manager @ Yahoo
  • 2. Who should attend this session? • If you are developing or planning to develop iOS apps and looking for tips to make your apps fast then you are right place. • Pre-requisite: Basic Objective-C knowledge
  • 3. Why performance is important? • Faster apps provide a better user experience • Users expect high performance • If your app is slow or unresponsive it is bound to get bad reviews and loose user base. • Remember, mobile devices have less RAM.
  • 4. Performance Tips • Use ARC • In addition to helping you avoid memory leaks, ARC can also improve your performance, by making sure that objects are de-allocated as soon as they are no longer needed. • These days, you should always use ARC in your projects!
  • 5. Performance Tips • Don’t block the main thread • You should never do any heavy lifting on the main thread. Remember, UIKit does all of its work on the main thread, such as drawing, managing touches, and responding to input. • Most cases of blocking the main thread occur when your app is performing an I/O operation which involves any task that needs to read or write from an external source, such as the disk or the network. • You can perform network tasks asynchronously by using this method on NSURLConnection
  • 6. Performance Tips • Use a reuseIdentifier where appropriate • A table view’s data source should generally reuse UITableViewCell objects when it assigns cells to rows. • Otherwise, table view will configure new cell each time a row is displayed. This is an expensive operation and will affect the scrolling performance of your app • To use reuseIdentifiers, call this method from your data source object when asked to provide a new cell for the table view: static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  • 7. Performance Tips • Avoid fat XIBs • If you are still using XIB files for some reason (may be for supporting pre iOS 5 devices) then make them as uncomplicated as possible. • Note that when you load a XIB into memory, all of its contents are loaded into memory, including any images. • If you have a view you’re not using immediately, then you’re wasting precious memory. • It’s worth noting that this won’t happen with storyboards, since a storyboard will only instantiate a view controller when it’s needed.
  • 8. Performance Tips • Size images to Image Views • Scaling images on the fly can be expensive, especially if your UIImageView is embedded in a UIScrollView. • If the image is downloaded from a remote service, sometimes you don’t have control over the size, or you might not be able to scale it on the server prior to downloading.
  • 9. Performance Tips • Choose the correct Collection • Learning to use the most appropriate class or object for the task at hand is fundamental to writing efficient code. This is especially true when dealing with collections. • There is a document on Apple’s Developer Library that explains in detail the differences between the available classes, as well as which situations suit each class. It’s a must read document for anyone looking to work with collections.
  • 10. Performance Tips • Enable GZIP compression • Speed up the download of network-based resources by enabling GZIP compression on both your server and on your client. • The good news is that iOS already supports GZIP compression by default if you’re using NSURLConnection, or a framework built on top of it such as AFNetworking. • There is a great article about GZIP compression which explains how to enable it on your Apache or IIS server.
  • 11. Performance Tips • Reuse and lazy Load Views • Create your views as you need them. • More views means more drawing; which ultimately means more CPU and memory overhead. This is especially true if your app embeds many views inside of a UIScrollView.
  • 12. Performance Tips • Cache what matters • Cache things that are unlikely to change, but are accessed frequently. • What can you cache? • Some candidates for caching are remote server responses, images. • NSURLConnection already caches resources on disk or in memory according to the HTTP headers it processes.
  • 13. Performance Tips • Handle memory warnings • iOS notifies all running apps when system memory is running low. • UIKit provides several ways to receive these low-memory warnings, including the following: • Implement the applicationDidReceiveMemoryWarning: method of your app delegate. • Override didReceiveMemoryWarning in your custom UIViewController subclass. • Register to receive the UIApplicationDidReceiveMemoryWarningNotification notification. • Upon receiving any of these warnings, free up any unnecessary memory. • Purge unused data structures, release any images that are not currently on-screen.
  • 14. Performance Tips • Reuse expensive Objects • Some objects are very slow to initialize — NSDateFormatter and NSCalendar are two examples. • To avoid performance bottlenecks when working with these objects, try to reuse these objects if at all possible. • You can do this by either adding a property to your class or using static
  • 15. Performance Tips • Optimize Your Table Views • Tips for optimizing Table Views • Reuse cells by setting the correct reuseIdentifier. • Make as many views opaque as possible, including the cell itself. • Avoid gradients, image scaling. • If the cell shows content that comes from the web, be sure to make those calls asynchronously and cache the responses. • Reduce the number of subviews. • Do as little work as possible in cellForRowAtIndexPath:. If you need to do some work, do it only once and cache the results. • Use the appropriate data structure to hold the information you need. Different structures have different costs for different operations.
  • 16. Performance Tips • Speed up launch time • Launching your app quickly is very important, especially when the user launches for the first time. First impressions mean a lot for an app! • Ensure your app starts as quickly as possible is to perform asynchronous tasks. • You need to strike a balance between what to fetch before app launch and what to fetch once the app is launched. • Try to avoid fat XIBs, since they’re loaded on the main thread. But recall that storyboards don’t have this problem — so use them if you can!
  • 17. Performance Tips • Cache Images (when?) • There are two common ways to load a UIImage from an app bundle. • Using imageNamed and second using imageWithContentsOfFile. • imageNamed has the advantage of caching the image as it’s loaded. • Alternately, imageWithContentsOfFile simply loads the image with no caching. • When would you use one over the other? • If you’re loading a large image that will be used only once, there’s no need to cache the image. • However, imageNamed is a much better choice for images that you’re going to be reusing in your app.
  • 18. Performance Tips • Reduce battery consumption • Optimize use of the following features: • The CPU • Wi-Fi, Bluetooth, and baseband (EDGE, 3G) radios • The Core Location framework • The accelerometers • The disk • Consider the following guidelines: • Avoid doing work that requires polling. • Avoid accessing the disk too frequently. • Do not draw to the screen faster than is needed. • Connect to external network servers only when needed, and do not poll those servers. • Disable location updates as soon as you can.
  • 19. Performance Tips • Reduce App’s memory footprint • Actions to take • Eliminate memory leaks. • Make resource files as small as possible. • Use Core Data or SQLite for large data sets. • Load resources lazily.
  • 20. Performance Tips • Use NSLog as sparingly as possible in production • Messages written using NSLog are presented in the debugger console and even to the device's console log in production. • NSLog() takes a non-negligible amount of time. • The following are commonly used log definitions that are used to selectively perform NSLog() in debug/production: #ifdef DEBUG // Only log when attached to the debugger # define DLog(...) NSLog(__VA_ARGS__) #else # define DLog(...) /* */ #endif // Always log, even in production #define ALog(...) NSLog(__VA_ARGS__)
  • 21. Performance Tips • Be Lazy • Defer memory allocations until you actually need the memory. • Defer reading the contents of a file until you actually need the information.
  • 22. Performance Tips • Take Advantage of Perceived Performance • The perception of performance is just as effective as actual performance in many cases. • Many program tasks can be performed in the background, using a dispatch queue, or at idle time. • Doing this keeps the application’s main thread free to handle user interactions and makes the program interface feel more responsive to the user. • If your program needs to scan a number of files or perform lengthy calculations, do so using a dispatch queue. • There is a good document available on apple’s site for Concurrency Programing
  • 23. Analyzing the performance • Using apple tools for analyzing performance • https ://developer.apple.com/library/ios/documentation/Performance/ Conceptual/PerformanceOverview/PerformanceTools/Performanc eTools.html#//apple_ref/doc/uid/TP40001410-CH205-BCIIHAAJ
  • 24. References Marcelo Fabri - 25 iOS App Performance Tips & Tricks. Retrieved from http://www.raywenderlich.com/31166/25-ios-app-performance-tips-tricks