Performance on iOS and watchOS
Description: Great performance is a prerequisite for delivering a compelling and immersive app experience that keeps users engaged. Learn best practices and strategies for characterizing and improving the performance of your code for iPhone, iPad, and Apple Watch.
Why should I think about performance?
It's a feature in your app that you should have on your mind all the time:
- Responsiveness delights and engages users
- Be a good neighbor, especially in Multitasking on iPad
- Efficient apps extend battery life
- Supports the whole range of iOS 9 hardware
Thinking About Performance
- Choosing technologies
- Know the technologies
- Pick the best ones for your app
- Apple technologies are optimized (we use them)
- Benifit from updating
- Taking measurements
- Animations: Instruments: Core Animation
- Responsiveness: Core instrumentation, Instruments: System Trace
- Don't ship your instrumentation: Create a copy of release scheme in Xcode, and define one additional define, so you could build a release version of the app with performance instrumentation quickly and easily.
- Collect start and end times: CFAbsoluteTimeGetCurrent
- Taps and button presses: IBAction, touchesEnded, UIGestureRecognizer target
- Tabs and modal views: viewWillAppear, viewDidAppear, will show how long it takes to display a the view.
- Memory: Xcode debugger, Instruments Allocations, Instruments Leaks
- Allocate, Reallocate memory takes time.
- Ref: iOS App Performance: Memory, WWDC12
- Ref: Improving Your App with Instruments, WWDC14
- Ref: Optimzing Your App Multitasking on iPad in iOS 9
- Allocate, Reallocate memory takes time.
- Memory: Xcode debugger, Instruments Allocations, Instruments Leaks
- Setting goals
- 60fps scrolling and animations.
- Respond to user actiosn in 100ms
- Performance Workflow
- Reproduce -> Profil -> Measure -> Change code -> Reproduce
- Profiling vs Measuring
- Profiling: Unsderstanding overall app activity
- Xcode debugger
- Instruments: Time Profiler
- Profiling: Unsderstanding overall app activity
- Measuring: Instrumenting a specific action
- CGAbsoluteTimeGetCurrent
- Instruments: System Trace
- Measuring: Instrumenting a specific action
- Avoid Using the Main Thread for
- CPU-intensive work
- Tasks that depend on external resource
- Avoid Using the Main Thread for
- Common Blocking Calls
- Any code path that ends up making a syscall
- Accessing resources not currently in memory: Disk I/O, Network access
- Waiting for work to complete on another thread
- Common Blocking Calls
- Networking:
NSURLConnection
and friends- Use asynchronous API
- Use GCD, Ref: Building Responsive and Efficient Apps with GCD
NSURLSession
background session
- Networking:
- Foundation initializers
- contentsOfFile:
- contentsOfURL:
- Foundation initializers
- Core Data
- Move some Core Data work to different concurrency modes. Ref: What's New in Core Data, Mission.
- Core Data
This note was originally published at github.com/antonio081014/WWDC_Learning_Review.