iOS Scroll Performance

Kyle Sherman
Kyle ShermanSr. Software Engineer at LinkedIn à LinkedIn
iOS Scroll
Performance
Kyle Sherman
LinkedIn iOS Developer
Don’t just blame a
technology
(i.e. Autolayout)
Measure!
Step 1: Use Instruments
to measure Scroll
Performance
Rule #1: Always
profile on device!
Setting Up Instruments
• Hit Command-I to Profile
• Or Product -> Profile
• Or Hold down Play button;
select Profile
• After done building (long
time), select Core Animation
• Turn on Device Utilization %
Setting Up Instruments
• Hit Command-I to Profile
• Or Product -> Profile
• Or Hold down Play button;
select Profile
• After done building (long
time), select Core Animation
• Turn on Device Utilization %
Setting Up Instruments
• Hit Command-I to Profile
• Or Product -> Profile
• Or Hold down Play button;
select Profile
• After done building (long
time), select Core Animation
• Turn on Device Utilization %
Profiling
• Tip #1: Decrease sample rate
• Hit the Record Button
• Tip #2: Set flags using
Command-Down arrow
• Tip #3: Double click flag to
name it
Profiling
• Tip #1: Decrease sample rate
• Hit the Record Button
• Tip #2: Set flags using
Command-Down arrow
• Tip #3: Double click flag to
name it
Profiling
• Tip #1: Decrease sample rate
• Hit the Record Button
• Tip #2: Set flags using
Command-Down arrow
• Tip #3: Double click flag to
name it
Profiling
• Tip #1: Decrease sample rate
• Hit the Record Button
• Tip #2: Set flags using
Command-Down arrow
• Tip #3: Single click flag to
name it
Step 2: Analyze
results
Examine Frame Rate
• Examine the frame rate
• Look at the CPU and GPU
usage at and around large
frame rate drops
Examine Frame Rate
• If Render/Device utilization is
high, requires more
investigation (details later)
• If not, and CPU usage is high:
• Click Time Profiler so CPU
usage is highlighted
• Drag around peak
• Look at heaviest stack trace
Step 3: Fix the
problem
GPU Issues
• GPU Issues require further
diagnosis
• Easiest way is to use Simulator
• Offscreen-Rendered is worst
performance hit (details to
come)
• Watch WWDC 2014 Session
419: Advanced Graphics and
Animations for iOS Apps
Step 4: Measure
Again!
Step 5: Repeat Steps
2, 3, & 4 until satisfied
Which brings us to our
concrete example…
Performant Circular
Images
Concrete Example:
Applying the skills learned
from the previous part, we
diagnose the issue(s)
Problem
Extremely Choppy Scrolling
in this view
Analyzing The Data
• Both the GPU utilization was high and CPU was
spiking
• I decided to investigate CPU usage first,
because it was possibly simpler to understand
• Saw suspicious methods and fixed issues in
code
Results
Frame rate increased very slightly
Re-measure!
GPU Issues
• Now it was time to resolve the GPU issues
• After watching WWDC 2014 Session 419,
learned about rendering pipeline and how bad
offscreen rendering is
• The following is a screenshot with Color
Offscreen-Rendered turned on
Color Offscreen-Rendered
On
Analysis
• Every single circle is
offscreen-rendered
• There are tons of circles on
the screen
• Need a more performant way
to make the circle
Test Hypothesis
Turn off circle creation
Yep!
After remeasuring, scrolling
is now smooth.
And look at Offscreen-
Rendered now!
Solutions
Solution #1
• In the WWDC session, Apple
suggests creating a mask like
the figure to the left of the
canvas
• Create the mask by drawing a
circle inside of a square of the
same size of the image
• Only fill outside of the circle
• The fill color of the mask must
be the same as the view (white
in this case)
• Place this mask on top of the
image (as a subview)
Image
Doesn’t work in this
case
Reason: Circles overlap
Solution #2
Retrieve circular images from API
Valid solution, but…
Adds to the number of images we serve (storage $$)
Solution #3
• Create a circular image mask and apply to the
image
• Perform on a background thread, so it doesn’t
block UI thread
Solution #3 (code)
https://gist.github.com/drumnkyle/c2ae34ea2422514c45d5
Solution #3 Tips
• Only do it once per image if possible
• You can process when image downloads or first
time it is used
• Add a circular version of the image to your
cache
Resources
• I highly recommend watching the WWDC video
mentioned. Maybe even a few times as it goes
into very good detail.
• Apple TV tech talks video Tuning your tvOS
Apps, also goes over these topics
https://developer.apple.com/videos/play/wwdc2014-419/
https://developer.apple.com/videos/play/techtalks-apple-tv/9/
1 sur 40

Contenu connexe

En vedette(20)

Skills To Make You An Effective ManagerSkills To Make You An Effective Manager
Skills To Make You An Effective Manager
Samuli Pahkala8.7K vues
Bubble gumBubble gum
Bubble gum
Ms Wilson11.6K vues
The JourneyThe Journey
The Journey
Cebu Missionary Foundation3.6K vues
Deep WebDeep Web
Deep Web
Ahmed Khan3K vues
Deep Web - what to do and what not to do	Deep Web - what to do and what not to do
Deep Web - what to do and what not to do
Cysinfo Cyber Security Community4K vues
Presentation on Medicated Chewing GumsPresentation on Medicated Chewing Gums
Presentation on Medicated Chewing Gums
Manoj Kumar Tekuri12K vues
Deep webDeep web
Deep web
ANKIT OJHA3.8K vues
Human BodyHuman Body
Human Body
Stacy Schanks34.2K vues
Impossible Is NothingImpossible Is Nothing
Impossible Is Nothing
Richard Dedor3.7K vues
Nobel prizeNobel prize
Nobel prize
asiyat19756.2K vues
10 facts about japan10 facts about japan
10 facts about japan
AbdAlrahman siyamek1.3K vues
Data made out of functionsData made out of functions
Data made out of functions
kenbot29.5K vues
Impossible is Nothing?Impossible is Nothing?
Impossible is Nothing?
Shriram Sivaramakrishnan1.4K vues

Similaire à iOS Scroll Performance

Ml goes fruitfulMl goes fruitful
Ml goes fruitfulPreeti Negi
415 vues48 diapositives
Evaluation Q6)Evaluation Q6)
Evaluation Q6)Yaquob1
169 vues7 diapositives
Evaluation – Question 5Evaluation – Question 5
Evaluation – Question 5A A
119 vues5 diapositives

Similaire à iOS Scroll Performance(20)

iOS Scroll Performance