developer tools #wwdc16€¦ · developer tools #wwdc16 session 418 using time profiler in...

99
© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Profile early, profile often Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel

Upload: others

Post on 22-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Profile early, profile often

Developer Tools #WWDC16

Session 418

Using Time Profiler in Instruments

Kris Markel

Page 2: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Agenda

Intro to profilingGoing fasterDoing lessImproving responsiveness

Page 3: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

A Better User Experience

Page 4: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness
Page 5: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness
Page 6: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness
Page 7: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

How much and what kind of work is my app doing?

Profiling

Page 8: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Time Profiler

Page 9: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Measure, adjust, repeatInstruments

Page 10: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Getting Started

Page 11: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

DemoProfiling an app

Page 12: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

method1

method2 method2 3 method2

Time

Page 13: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

method1

method2 method2 3 method2

Time

Page 14: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

method1

method2 method2 3 method2

Time

Page 15: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2 method2 3 method2

Time

Page 16: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2 method2 3 method2

main()

method1()

method2()

1

1

1

Time

Page 17: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2 method2 3 method2

main()

method1()

method2()

1

1

1

Time

Page 18: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2 method2 3 method2

main()

method1()

method2()

1

1

1

Time

Page 19: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 ms

main()

method1()

method2()

1

1

1

Time

Page 20: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 msTime

main()

method1()

method2()

2

2

2

Page 21: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 msTime

main()

method1()

method2()

2

2

2

Page 22: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 msTime

main()

method1()

method2()

2

2

2

Page 23: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

main()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 msTime

main()

method1()

method2()

2

2

2

Page 24: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

main()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

1 msTime

main()

method1()

method2()

method2()

3

2

2

1

Page 25: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

main()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

main()

method1()

method2()

main()

method1()

method2()

1 msTime

main()

method1()

method2()

method2()

3

2

2

1

Page 26: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

main

method1 method2

method2 3 3

main()

method1()

method2()

main()

method2()

method1

method2

main()

method1()

method2()

method2 3 method2

main()

method1()

method2()

main()

method1()

method2()

1 msTime

main()

method1()

method2()

method2()

5

4

4

1

Page 27: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

main()

method1()

method2()

method2()

5

4

4

1

Page 28: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure duration

main()

method1()

method2()

method2()

5

4

4

1

Page 29: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure durationAggregates samples into a useful summary

main()

method1()

method2()

method2()

5

4

4

1

Page 30: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure durationAggregates samples into a useful summary• Long running vs. repetitive main()

method1()

method2()

method2()

5

4

4

1

Page 31: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure durationAggregates samples into a useful summary• Long running vs. repetitive main()

method1()

method2()

method2()

5

4

4

1

Page 32: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure durationAggregates samples into a useful summary• Long running vs. repetitive

Focuses on CPU usage

main()

method1()

method2()

method2()

5

4

4

1

Page 33: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

The Call Tree

Doesn’t measure durationAggregates samples into a useful summary• Long running vs. repetitive

Focuses on CPU usage• Doesn’t capture everything

main()

method1()

method2()

method2()

5

4

4

1

Page 34: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

DemoGoing faster and doing less

Page 35: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Starting the Investigation

Look for the unexpected• Trackpad friendly• Drag to apply a filter• Draggable filter edges• Option-drag to zoom in control-drag to zoom out• Data values on hover

Page 36: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Page 37: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster

Page 38: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage

Page 39: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening

Page 40: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening• Walked back to our code

Page 41: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening• Walked back to our code• Inspected our code

Page 42: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening• Walked back to our code• Inspected our code• Made it faster

Page 43: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening• Walked back to our code• Inspected our code• Made it faster• Verified the changes

Page 44: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Going faster• Focused on an area of high CPU usage• Examined the call tree, looking for where the work was happening• Walked back to our code• Inspected our code• Made it faster• Verified the changes• Saved the user’s time

Page 45: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Page 46: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less

Page 47: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage

Page 48: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage• Examined the call tree

Page 49: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage• Examined the call tree• Determined the frameworks involved

Page 50: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage• Examined the call tree• Determined the frameworks involved• Stopped doing unnecessary work

Page 51: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage• Examined the call tree• Determined the frameworks involved• Stopped doing unnecessary work• Verified the changes

Page 52: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Doing less• Focused on low, but unexpected CPU usage• Examined the call tree• Determined the frameworks involved• Stopped doing unnecessary work• Verified the changes• Improved battery life

Page 53: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

Page 54: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

Page 55: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work

Page 56: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events

Page 57: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance

Page 58: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain

Page 59: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 60: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 61: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 62: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 63: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 64: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 65: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

The main thread does all the UI work• Run loop waiting for events• Sends events to your UIApplication instance• Passes through the responder chain• Your code gets invoked

Page 66: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

Page 67: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

When busy, the main thread can’t process events

Page 68: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

When busy, the main thread can’t process events• The queue backs up

Page 69: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

When busy, the main thread can’t process events• The queue backs up• Stuttering and hiccups

Page 70: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

When busy, the main thread can’t process events• The queue backs up• Stuttering and hiccups• App becomes unresponsive

Page 71: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Responsiveness

When busy, the main thread can’t process events• The queue backs up• Stuttering and hiccups• App becomes unresponsive

Keep the main thread free

Page 72: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

DemoImproving responsiveness

Page 73: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Page 74: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness

Page 75: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes

Page 76: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes• Focused on the main thread

Page 77: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes• Focused on the main thread• Identified non-UI work happening on the main thread

Page 78: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes• Focused on the main thread• Identified non-UI work happening on the main thread• Distributed the work across multiple threads

Page 79: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes• Focused on the main thread• Identified non-UI work happening on the main thread• Distributed the work across multiple threads• Verified the changes

Page 80: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

What We Did

Responsiveness• Examined the CPU spikes• Focused on the main thread• Identified non-UI work happening on the main thread• Distributed the work across multiple threads• Verified the changes• Achieved a better user experience

Page 81: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Regarding Optimization

Page 82: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Regarding Optimization

The fixes were simple, but added complexity

Page 83: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Regarding Optimization

The fixes were simple, but added complexity By finding them early in the development process, there’s more time to verify correctness

Page 84: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Regarding Optimization

The fixes were simple, but added complexity By finding them early in the development process, there’s more time to verify correctnessProfile early, profile often!

Page 85: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Regarding Optimization

The fixes were simple, but added complexity By finding them early in the development process, there’s more time to verify correctnessProfile early, profile often!Sometimes get big gains for little effort

Page 86: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Best Practices

Always profile release buildsAlways profile on the deviceRun with old devicesUse large data sets where it makes sense• Look for poorly scaling code (O(n2), etc.)

Page 87: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

Page 88: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …

Page 89: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

Page 90: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application

Page 91: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application- Better battery life

Page 92: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application- Better battery life- More responsive UI

Page 93: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application- Better battery life- More responsive UI

Then you should …

Page 94: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application- Better battery life- More responsive UI

Then you should …• Profile early

Page 95: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Summary

If you want …• The best experience for your users across all the devices you support

- A faster application- Better battery life- More responsive UI

Then you should …• Profile early• Profile often

Page 96: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

More Information

https://developer.apple.com/wwdc16/418

Page 97: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Related Sessions

Optimizing App Startup Time Mission Wednesday 10:00AM

System Trace in Depth Nob Hill Thursday 9:00AM

Thread Sanitizer and Static Analysis Mission Thursday 10:00AM

Optimizing I/O for Performance and Battery Life Nob Hill Friday 11:00AM

Concurrent Programming with GCD in Swift 3 Pacific Heights Friday 4:00PM

Unified Logging and Activity Tracing Nob Hill Friday 5:00PM

Profiling in Depth WWDC 2015

Page 98: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness

Labs

Xcode Open Hours Developer Tools Lab B Friday 3:00PM

Swift Open Hours Developer Tools Lab A Friday 3:00PM

Page 99: Developer Tools #WWDC16€¦ · Developer Tools #WWDC16 Session 418 Using Time Profiler in Instruments Kris Markel. Agenda Intro to profiling Going faster Doing less Improving responsiveness