SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
iOS Performance
tips and tricks to do it better
Julian Król
iOS Software Engineer @ Miquido
Overview
• We get more powerful devices but create more
complex apps
• We want to keep UI highly responsive
• Present valuable content ASAP
– Ralph Marston (http://www.brainyquote.com)
“Don't lower your expectations to meet your
performance. Raise your level of
performance to meet your expectations.”
Most general
Avoid blocking main thread whenever it is possible, put the hard computing to
background and on the man thread update UI
!
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//work to be done in background (for example data parsing or retrieving)
dispatch_async(dispatch_get_main_queue(), ^{
//updating UI when the expensive work is finished on the background thread
});
});
!
reuseIdentifier
Probably everyone knows that but for clarity:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"CellIdentifier";
JKMyCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
//if cell was not created so far then initialise it
if (!cell) {
cell = [[NSBundle mainBundle] loadNibNamed:@"JKMyCell" owner:nil options:nil][0];
}
//in other case only update - do not allocate it every time!
JKModelObject *obj = [self getObjectAtIndexPath:indexPath];// retrieving model object to update cell
[cell update:obj]; //update cell every time it gets called to the view
return cell;
}
Creation & Caching
• avoid recreation of big and slow objects,
example: NSDateFormatter and re-setting its
format
• create (reusable) objects once and reuse
whenever possible (a few date formatters
depending on number of date formats)
Collections and enumeration
• Chose the right collection for the job!
• Be aware of how many collections are waiting for you to play
(NSArray, NSDictionary and NSSet are not the only one,
believe me!)
• General rule: arrays (fast access by index, slow to lookup by
value, as well as in insert and delete operations);
dictionaries (quick access to object by a key), sets (quick
access by a value, efficient in delete and insert operations)
• although filteredArrayUsingPredicate method looks fancy it
is very slow!
for more details click here
Shadows - common mistake
• Do not add shadows in that way:
view.layer.shadowOffset = CGSizeMake(1.f, 1.f);
view.layer.shadowRadius = 10.f;
• Use bezier path instead:
view.layer.shadowPath = [[UIBezierPath bezierPathWithRect:view.bounds] CGPath];
Not convinced? Checked it with cells in UITableView
while fast scrolling :)
Images - general rules
!
• while adding images existing on device use UIImage
imageNamed: rather than UIImage
imageWithContentsOfFile - first one uses caching!
• [UIColor colorWithPatternImage:] - fine as long as image
is relatively small comparing to the surface it will fulfil
otherwise use UIImageView which corresponds to the
image size
• use placeholder while loading (in the background!)
content from the web
Network communication
• again(!), do not block main thread!
• Try some external libraries (AFNetworking highly
recommended)
• avoid synchronous calls
• cache responses if it make sense to avoid
reloading it
@autoreleasepool
• the whole app is in one
• in most cases you can avoid creating many
temporary objects
• if you can not, consider @autoreleasepool
(example later on)
Other notices
• - (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -
do not use it to initialise the whole world,
• most of the objects, managers etc can wait with its initialisation
till the very first usage
• accessing ivars is a bit faster than properties (I personally avoid
properties)
• handle memory warning situations
• in most cases any delegate should be weak - avoid retail cycle
counts
PROFILER!!
For improvement testing as well as looking for
bottlenecks use profiler which is provided with
Xcode
Most useful:
!
• allocations
• time profiler
• leaks
It’s time for a short demo about
measuring performance
improvement with Xcode's profiler
Sources and inspirations
• http://www.raywenderlich.com/31166/25-ios-
app-performance-tips-tricks
• http://www.objc.io/issue-7/collections.html
Thanks for the
attention

Contenu connexe

Tendances

Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer Hiroshi SHIBATA
 
Machine Learning for Web Developers
Machine Learning for Web DevelopersMachine Learning for Web Developers
Machine Learning for Web DevelopersRiza Fahmi
 
Introduction to Docker session (at Nairuby meetup)
Introduction to Docker session (at Nairuby meetup)Introduction to Docker session (at Nairuby meetup)
Introduction to Docker session (at Nairuby meetup)Stanley Ndagi
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance DrupalJeff Geerling
 
JavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceJavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceDmitry Sheiko
 
How to Use WebVR to Enhance the Web Experience
How to Use WebVR to Enhance the Web ExperienceHow to Use WebVR to Enhance the Web Experience
How to Use WebVR to Enhance the Web ExperienceFITC
 
Going Node.js at Netflix
Going Node.js at NetflixGoing Node.js at Netflix
Going Node.js at Netflixmicahr
 
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...Adam Grocholski
 
Deploying Your Favorite Web App To AWS Lambda with Apex up
Deploying Your Favorite Web App To AWS Lambda with Apex upDeploying Your Favorite Web App To AWS Lambda with Apex up
Deploying Your Favorite Web App To AWS Lambda with Apex upRiza Fahmi
 

Tendances (10)

Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Machine Learning for Web Developers
Machine Learning for Web DevelopersMachine Learning for Web Developers
Machine Learning for Web Developers
 
Introduction to Docker session (at Nairuby meetup)
Introduction to Docker session (at Nairuby meetup)Introduction to Docker session (at Nairuby meetup)
Introduction to Docker session (at Nairuby meetup)
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
JavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right ChoiceJavaScript MV* Framework - Making the Right Choice
JavaScript MV* Framework - Making the Right Choice
 
How to Use WebVR to Enhance the Web Experience
How to Use WebVR to Enhance the Web ExperienceHow to Use WebVR to Enhance the Web Experience
How to Use WebVR to Enhance the Web Experience
 
Going Node.js at Netflix
Going Node.js at NetflixGoing Node.js at Netflix
Going Node.js at Netflix
 
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...
St. Louis Day of .NET 2013 - Building Your Dev and Test Sandbox with Windows ...
 
Node
NodeNode
Node
 
Deploying Your Favorite Web App To AWS Lambda with Apex up
Deploying Your Favorite Web App To AWS Lambda with Apex upDeploying Your Favorite Web App To AWS Lambda with Apex up
Deploying Your Favorite Web App To AWS Lambda with Apex up
 

Similaire à iOS performance: tips and tricks to do it better

2013-05-15 threads. why and how
2013-05-15 threads. why and how2013-05-15 threads. why and how
2013-05-15 threads. why and howCocoaHeads Tricity
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextMugunth Kumar
 
iOS App performance - Things to take care
iOS App performance - Things to take careiOS App performance - Things to take care
iOS App performance - Things to take careGurpreet Singh Sachdeva
 
Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Saulo Arruda
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOSMake School
 
Cocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsCocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsMaciej Burda
 
Responsive & Responsible: Implementing Responsive Design at Scale
Responsive & Responsible: Implementing Responsive Design at ScaleResponsive & Responsible: Implementing Responsive Design at Scale
Responsive & Responsible: Implementing Responsive Design at Scalescottjehl
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSébastien Levert
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practicesAlessio Ricco
 
08 mobile development
08   mobile development08   mobile development
08 mobile developmentdarwinodb
 
Corso WebApp iOS - Lezione 07: iOS WebApp Anatomy
Corso WebApp iOS - Lezione 07: iOS WebApp AnatomyCorso WebApp iOS - Lezione 07: iOS WebApp Anatomy
Corso WebApp iOS - Lezione 07: iOS WebApp AnatomyAndrea Picchi
 
iOS Development For Android Developers
iOS Development For Android DevelopersiOS Development For Android Developers
iOS Development For Android DevelopersDarryl Bayliss
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...olrandir
 
iOS Course day 2
iOS Course day 2iOS Course day 2
iOS Course day 2Rich Allen
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: IntroductionInnerFood
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applicationslmrei
 
HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)Andi Farr
 
Background Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofBackground Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofmoliver816
 
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...Sébastien Levert
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS IntrodructionDavid Ličen
 

Similaire à iOS performance: tips and tricks to do it better (20)

2013-05-15 threads. why and how
2013-05-15 threads. why and how2013-05-15 threads. why and how
2013-05-15 threads. why and how
 
Hi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreTextHi performance table views with QuartzCore and CoreText
Hi performance table views with QuartzCore and CoreText
 
iOS App performance - Things to take care
iOS App performance - Things to take careiOS App performance - Things to take care
iOS App performance - Things to take care
 
Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4
 
Multithreading on iOS
Multithreading on iOSMultithreading on iOS
Multithreading on iOS
 
Cocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design PatternsCocoa Heads Tricity - Design Patterns
Cocoa Heads Tricity - Design Patterns
 
Responsive & Responsible: Implementing Responsive Design at Scale
Responsive & Responsible: Implementing Responsive Design at ScaleResponsive & Responsible: Implementing Responsive Design at Scale
Responsive & Responsible: Implementing Responsive Design at Scale
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
08 mobile development
08   mobile development08   mobile development
08 mobile development
 
Corso WebApp iOS - Lezione 07: iOS WebApp Anatomy
Corso WebApp iOS - Lezione 07: iOS WebApp AnatomyCorso WebApp iOS - Lezione 07: iOS WebApp Anatomy
Corso WebApp iOS - Lezione 07: iOS WebApp Anatomy
 
iOS Development For Android Developers
iOS Development For Android DevelopersiOS Development For Android Developers
iOS Development For Android Developers
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
 
iOS Course day 2
iOS Course day 2iOS Course day 2
iOS Course day 2
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: Introduction
 
Developing iOS REST Applications
Developing iOS REST ApplicationsDeveloping iOS REST Applications
Developing iOS REST Applications
 
HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)
 
Background Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard ofBackground Fetch - the most powerful API you've never heard of
Background Fetch - the most powerful API you've never heard of
 
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 

Dernier

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Dernier (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

iOS performance: tips and tricks to do it better

  • 1. iOS Performance tips and tricks to do it better Julian Król iOS Software Engineer @ Miquido
  • 2. Overview • We get more powerful devices but create more complex apps • We want to keep UI highly responsive • Present valuable content ASAP
  • 3. – Ralph Marston (http://www.brainyquote.com) “Don't lower your expectations to meet your performance. Raise your level of performance to meet your expectations.”
  • 4. Most general Avoid blocking main thread whenever it is possible, put the hard computing to background and on the man thread update UI ! dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //work to be done in background (for example data parsing or retrieving) dispatch_async(dispatch_get_main_queue(), ^{ //updating UI when the expensive work is finished on the background thread }); }); !
  • 5. reuseIdentifier Probably everyone knows that but for clarity: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"CellIdentifier"; JKMyCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; //if cell was not created so far then initialise it if (!cell) { cell = [[NSBundle mainBundle] loadNibNamed:@"JKMyCell" owner:nil options:nil][0]; } //in other case only update - do not allocate it every time! JKModelObject *obj = [self getObjectAtIndexPath:indexPath];// retrieving model object to update cell [cell update:obj]; //update cell every time it gets called to the view return cell; }
  • 6. Creation & Caching • avoid recreation of big and slow objects, example: NSDateFormatter and re-setting its format • create (reusable) objects once and reuse whenever possible (a few date formatters depending on number of date formats)
  • 7. Collections and enumeration • Chose the right collection for the job! • Be aware of how many collections are waiting for you to play (NSArray, NSDictionary and NSSet are not the only one, believe me!) • General rule: arrays (fast access by index, slow to lookup by value, as well as in insert and delete operations); dictionaries (quick access to object by a key), sets (quick access by a value, efficient in delete and insert operations) • although filteredArrayUsingPredicate method looks fancy it is very slow! for more details click here
  • 8. Shadows - common mistake • Do not add shadows in that way: view.layer.shadowOffset = CGSizeMake(1.f, 1.f); view.layer.shadowRadius = 10.f; • Use bezier path instead: view.layer.shadowPath = [[UIBezierPath bezierPathWithRect:view.bounds] CGPath]; Not convinced? Checked it with cells in UITableView while fast scrolling :)
  • 9. Images - general rules ! • while adding images existing on device use UIImage imageNamed: rather than UIImage imageWithContentsOfFile - first one uses caching! • [UIColor colorWithPatternImage:] - fine as long as image is relatively small comparing to the surface it will fulfil otherwise use UIImageView which corresponds to the image size • use placeholder while loading (in the background!) content from the web
  • 10. Network communication • again(!), do not block main thread! • Try some external libraries (AFNetworking highly recommended) • avoid synchronous calls • cache responses if it make sense to avoid reloading it
  • 11. @autoreleasepool • the whole app is in one • in most cases you can avoid creating many temporary objects • if you can not, consider @autoreleasepool (example later on)
  • 12. Other notices • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - do not use it to initialise the whole world, • most of the objects, managers etc can wait with its initialisation till the very first usage • accessing ivars is a bit faster than properties (I personally avoid properties) • handle memory warning situations • in most cases any delegate should be weak - avoid retail cycle counts
  • 13. PROFILER!! For improvement testing as well as looking for bottlenecks use profiler which is provided with Xcode Most useful: ! • allocations • time profiler • leaks
  • 14. It’s time for a short demo about measuring performance improvement with Xcode's profiler
  • 15. Sources and inspirations • http://www.raywenderlich.com/31166/25-ios- app-performance-tips-tricks • http://www.objc.io/issue-7/collections.html