SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
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
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
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...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 

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