SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Instruments.
wednesday.is
wednesday.is
1. Make it work
2. Make it right
3. Make it fast
- Brian W. Kernighan
3
Today’s Plan
What we’ll be covering
What Instruments is and why do we use it
How to check your code for performance
issues and memory issues
The best way to debug these
issues
wednesday.is
iOS is so fast, why
bother
What is instruments
Instruments is a powerful performance
analysis and testing tool that's part of
Xcode toolset. Instruments can help you
profile your apps on all platforms - iOS,
macOS, watchOS, tvOS - in order to
better understand and optimize their
behavior and performance.
Why do we need to use it ?
• Track down problems in your source code
• Analyze the performance of your app
• Find memory problems
wednesday.is
Let’s get started with a
sample app
You can access the instruments by using
Product ➔ Profile from the Xcode
menu for which the shortcut handle is ⌘ + I.
This will rebuild your product and opens the
Xcode Instruments overview.
wednesday.is
How can I access Xcode
Instruments?
An overview which shows 17 di
ff
erent instruments
An overview which shows 17 di
ff
erent instruments
wednesday.is
Time Profiler
1- Recording controls:The record button stops and starts the app
currently under test.
2 - Run timer:The timer counts how long the profiled app has been
running and how many times it has run.
3 - Instrument track:This is theTime Profiler track.You’ll learn more
about the specifics of the graph later.
4 - Detail panel:This shows the main information about the particular
instrument you’re using. In this case, it shows the ones using the most
CPU time.
5 - Inspectors panel:There are two inspectors — Extended Detail
and Run Info
wednesday.is
it spends a lot of time invoking the method that creates the CGImage output after applying
the image filter.
Problem
wednesday.is
To Solve this we can do two things
1- First, offload the image filtering onto a background thread
with DispatchQueue.global().async
2 - cache each image after it’s generated.
wednesday.is
1- Check to see if a filtered image for this photo exists
in the image cache. If yes, display that image.
2 - If not, dispatch the call to create an image with the
tonal filter onto a background queue.This allows the
UI to remain responsive while the filter runs. When
the filter completes, save the image in the cache and
update the image view on the main queue.
wednesday.is
We can do the same for
original Flickr thumbnails.
If an image already exists in
the cache, call the completion
closure straight away with the
cached image. Otherwise,
load the image from Flickr and
store it in the cache.
wednesday.is
Allocations
You have likely heard about memory leaks!
One of the type is Unbounded memory
growth
wednesday.is
Unbounded memory growth
This occurs when memory is allocated continuously and never given a chance to be deallocated.
If this continues unchecked, you’ll run out of memory. On iOS, this means the system will
terminate your app.
wednesday.is
So, How can we prevent
memory leak using
instruments?
wednesday.is
To start fresh with a new instruments profile, quit the
Instruments app
Press Command-I in Xcode, select Allocations from
the list and press Choose.
WithAllocations running, perform five different searches
in the app.
Make sure you have some results and let the app settle
a bit by waiting for a few minutes
wednesday.is
- This adds an image to a dictionary, keyed on the
photo ID of the Flickr photo.
- But you’ll notice the image is never cleared from
that dictionary!
- That’s where your unbounded memory growth is
coming from. Everything is working as it should,
but the app never removes things from the cache
it only ever adds them!
Example of Unbounded memory growth
wednesday.is
- To fix the problem, have ImageCache listen for the
memory warning notification UIApplication fires.
- When ImageCache receives this, it should clear its
cache.This registers an observer for
UIApplication.didReceiveMemoryWarningNotification to
execute a closure that clears images.
- All the code needs to do is remove all objects in the
cache.This ensures nothing is holding onto the images
anymore and they’ll be deallocated.
Solution
wednesday.is
Bonus tip!
Always profile your app on an actual device instead of the simulator.The iOS
simulator has all the horsepower of your Mac behind it, whereas a device has all the
limitations of mobile hardware.That said, your app may seem to run fine in the
simulator, but you might discover a performance issue once it’s running on a real
device.
19
Key Takeaways
What we learned
What is instruments? Why is it needed!
How to check CPU usage usingTime
profiler
Types of memory leaks and how to detect
them usingAllocation
Some optimizations to improve
app performance
Thank you
very much!!!
wednesday.is

Contenu connexe

Similaire à Master iOS Performance Optimization with Instruments

La1 information and communication technology and society
La1   information and communication technology and societyLa1   information and communication technology and society
La1 information and communication technology and societyAzmiah Mahmud
 
Learning area 1_-_information_and_communication_technology_and_society
Learning area 1_-_information_and_communication_technology_and_societyLearning area 1_-_information_and_communication_technology_and_society
Learning area 1_-_information_and_communication_technology_and_societySaktis Kesavan
 
Learning area 1 information and communication technology and society
Learning area 1   information and communication technology and societyLearning area 1   information and communication technology and society
Learning area 1 information and communication technology and societyShuren Lew
 
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...Codemotion
 
iOS Scroll Performance
iOS Scroll PerformanceiOS Scroll Performance
iOS Scroll PerformanceKyle Sherman
 
React Native Android. It's easy.
React Native Android. It's easy.React Native Android. It's easy.
React Native Android. It's easy.Cameron Moss
 
Best Practice iPhone SDK App Design
Best Practice iPhone SDK App DesignBest Practice iPhone SDK App Design
Best Practice iPhone SDK App DesignBess Ho
 
Pixlr and small apps in the classroom
Pixlr and small apps in the classroomPixlr and small apps in the classroom
Pixlr and small apps in the classroomArtfulArtsyAmy
 
Wids datathon slides_vanim (updated)
Wids datathon slides_vanim (updated)Wids datathon slides_vanim (updated)
Wids datathon slides_vanim (updated)Vani Mandava
 
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...Andrey Karpov
 
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...Concentrated Technology
 
Practical guide to optimization in Unity
Practical guide to optimization in UnityPractical guide to optimization in Unity
Practical guide to optimization in UnityDevGAMM Conference
 
Smalltalk in the pocket - Building applications for the iPhone
Smalltalk in the pocket - Building applications for the iPhoneSmalltalk in the pocket - Building applications for the iPhone
Smalltalk in the pocket - Building applications for the iPhoneEsteban Lorenzano
 
3 - Thermometer.pptx thermometer thermometer thermometer
3 - Thermometer.pptx thermometer thermometer thermometer3 - Thermometer.pptx thermometer thermometer thermometer
3 - Thermometer.pptx thermometer thermometer thermometeraustcornish143
 
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
So. many. vulnerabilities. Why are containers such a mess and what to do abou...So. many. vulnerabilities. Why are containers such a mess and what to do abou...
So. many. vulnerabilities. Why are containers such a mess and what to do abou...Eric Smalling
 
0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS EnvironmentsSecuRing
 
Ml goes fruitful
Ml goes fruitfulMl goes fruitful
Ml goes fruitfulPreeti Negi
 

Similaire à Master iOS Performance Optimization with Instruments (20)

La1 information and communication technology and society
La1   information and communication technology and societyLa1   information and communication technology and society
La1 information and communication technology and society
 
Learning area 1_-_information_and_communication_technology_and_society
Learning area 1_-_information_and_communication_technology_and_societyLearning area 1_-_information_and_communication_technology_and_society
Learning area 1_-_information_and_communication_technology_and_society
 
Learning area 1 information and communication technology and society
Learning area 1   information and communication technology and societyLearning area 1   information and communication technology and society
Learning area 1 information and communication technology and society
 
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
Tech Webinar: Offline First: Creare un'app Phonegap che funzioni offline e si...
 
iOS Scroll Performance
iOS Scroll PerformanceiOS Scroll Performance
iOS Scroll Performance
 
React Native Android. It's easy.
React Native Android. It's easy.React Native Android. It's easy.
React Native Android. It's easy.
 
Best Practice iPhone SDK App Design
Best Practice iPhone SDK App DesignBest Practice iPhone SDK App Design
Best Practice iPhone SDK App Design
 
Pixlr and small apps in the classroom
Pixlr and small apps in the classroomPixlr and small apps in the classroom
Pixlr and small apps in the classroom
 
Wids datathon slides_vanim (updated)
Wids datathon slides_vanim (updated)Wids datathon slides_vanim (updated)
Wids datathon slides_vanim (updated)
 
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
PVS-Studio Now Supports Any Build System under Windows and Any Compiler. Easy...
 
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...
TechMentor Fall, 2011 - How to Resolve (Nearly) Every Windows 7 Application I...
 
Practical guide to optimization in Unity
Practical guide to optimization in UnityPractical guide to optimization in Unity
Practical guide to optimization in Unity
 
Smalltalk in the pocket - Building applications for the iPhone
Smalltalk in the pocket - Building applications for the iPhoneSmalltalk in the pocket - Building applications for the iPhone
Smalltalk in the pocket - Building applications for the iPhone
 
3 - Thermometer.pptx thermometer thermometer thermometer
3 - Thermometer.pptx thermometer thermometer thermometer3 - Thermometer.pptx thermometer thermometer thermometer
3 - Thermometer.pptx thermometer thermometer thermometer
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
So. many. vulnerabilities. Why are containers such a mess and what to do abou...So. many. vulnerabilities. Why are containers such a mess and what to do abou...
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
 
Performence #2 gpu
Performence #2  gpuPerformence #2  gpu
Performence #2 gpu
 
0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments
 
Agility Requires Safety
Agility Requires SafetyAgility Requires Safety
Agility Requires Safety
 
Ml goes fruitful
Ml goes fruitfulMl goes fruitful
Ml goes fruitful
 

Plus de Wednesday Solutions

What is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWhat is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWednesday Solutions
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorWednesday Solutions
 
Create Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsCreate Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsWednesday Solutions
 
What is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWhat is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWednesday Solutions
 

Plus de Wednesday Solutions (8)

Error Handling in Express
Error Handling in ExpressError Handling in Express
Error Handling in Express
 
What is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A WalkthroughWhat is React Concurrent Mode: A Walkthrough
What is React Concurrent Mode: A Walkthrough
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage Collector
 
Create Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.jsCreate Basic 3D Scenes Using Three.js
Create Basic 3D Scenes Using Three.js
 
A Guide to Figma for Developers
A Guide to Figma for DevelopersA Guide to Figma for Developers
A Guide to Figma for Developers
 
What is Temporal: Workflow & Cluster
What is Temporal: Workflow & ClusterWhat is Temporal: Workflow & Cluster
What is Temporal: Workflow & Cluster
 
Vector Embedding using AI
Vector Embedding using AIVector Embedding using AI
Vector Embedding using AI
 
What is GraphQL: Best Practices
What is GraphQL: Best PracticesWhat is GraphQL: Best Practices
What is GraphQL: Best Practices
 

Dernier

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Dernier (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 

Master iOS Performance Optimization with Instruments

  • 2. wednesday.is 1. Make it work 2. Make it right 3. Make it fast - Brian W. Kernighan
  • 3. 3 Today’s Plan What we’ll be covering What Instruments is and why do we use it How to check your code for performance issues and memory issues The best way to debug these issues
  • 4. wednesday.is iOS is so fast, why bother What is instruments Instruments is a powerful performance analysis and testing tool that's part of Xcode toolset. Instruments can help you profile your apps on all platforms - iOS, macOS, watchOS, tvOS - in order to better understand and optimize their behavior and performance. Why do we need to use it ? • Track down problems in your source code • Analyze the performance of your app • Find memory problems
  • 6. You can access the instruments by using Product ➔ Profile from the Xcode menu for which the shortcut handle is ⌘ + I. This will rebuild your product and opens the Xcode Instruments overview. wednesday.is How can I access Xcode Instruments? An overview which shows 17 di ff erent instruments An overview which shows 17 di ff erent instruments
  • 7. wednesday.is Time Profiler 1- Recording controls:The record button stops and starts the app currently under test. 2 - Run timer:The timer counts how long the profiled app has been running and how many times it has run. 3 - Instrument track:This is theTime Profiler track.You’ll learn more about the specifics of the graph later. 4 - Detail panel:This shows the main information about the particular instrument you’re using. In this case, it shows the ones using the most CPU time. 5 - Inspectors panel:There are two inspectors — Extended Detail and Run Info
  • 8. wednesday.is it spends a lot of time invoking the method that creates the CGImage output after applying the image filter. Problem
  • 9. wednesday.is To Solve this we can do two things 1- First, offload the image filtering onto a background thread with DispatchQueue.global().async 2 - cache each image after it’s generated.
  • 10. wednesday.is 1- Check to see if a filtered image for this photo exists in the image cache. If yes, display that image. 2 - If not, dispatch the call to create an image with the tonal filter onto a background queue.This allows the UI to remain responsive while the filter runs. When the filter completes, save the image in the cache and update the image view on the main queue.
  • 11. wednesday.is We can do the same for original Flickr thumbnails. If an image already exists in the cache, call the completion closure straight away with the cached image. Otherwise, load the image from Flickr and store it in the cache.
  • 12. wednesday.is Allocations You have likely heard about memory leaks! One of the type is Unbounded memory growth
  • 13. wednesday.is Unbounded memory growth This occurs when memory is allocated continuously and never given a chance to be deallocated. If this continues unchecked, you’ll run out of memory. On iOS, this means the system will terminate your app.
  • 14. wednesday.is So, How can we prevent memory leak using instruments?
  • 15. wednesday.is To start fresh with a new instruments profile, quit the Instruments app Press Command-I in Xcode, select Allocations from the list and press Choose. WithAllocations running, perform five different searches in the app. Make sure you have some results and let the app settle a bit by waiting for a few minutes
  • 16. wednesday.is - This adds an image to a dictionary, keyed on the photo ID of the Flickr photo. - But you’ll notice the image is never cleared from that dictionary! - That’s where your unbounded memory growth is coming from. Everything is working as it should, but the app never removes things from the cache it only ever adds them! Example of Unbounded memory growth
  • 17. wednesday.is - To fix the problem, have ImageCache listen for the memory warning notification UIApplication fires. - When ImageCache receives this, it should clear its cache.This registers an observer for UIApplication.didReceiveMemoryWarningNotification to execute a closure that clears images. - All the code needs to do is remove all objects in the cache.This ensures nothing is holding onto the images anymore and they’ll be deallocated. Solution
  • 18. wednesday.is Bonus tip! Always profile your app on an actual device instead of the simulator.The iOS simulator has all the horsepower of your Mac behind it, whereas a device has all the limitations of mobile hardware.That said, your app may seem to run fine in the simulator, but you might discover a performance issue once it’s running on a real device.
  • 19. 19 Key Takeaways What we learned What is instruments? Why is it needed! How to check CPU usage usingTime profiler Types of memory leaks and how to detect them usingAllocation Some optimizations to improve app performance