Slide 1

Slide 1 text

Performance Optimization Vitalii Topoliuk @vtopoliuk

Slide 2

Slide 2 text

- Performance scenarios - How to measure performance - How to improve key scenarios - Tips and Tricks Contents:

Slide 3

Slide 3 text

- Not just about speed - CPU tasks - Memory - Rendering - File I/O - Networking - Power Performance Performance scenarios

Slide 4

Slide 4 text

- Not just about speed - CPU tasks - Memory - Rendering - File I/O - Networking - Power Performance Performance scenarios

Slide 5

Slide 5 text

Overall recommendations Performance scenarios - Don’t guess, just measure - Measure on slowest device - Measure on pessimistic data - Measure on real data

Slide 6

Slide 6 text

How to measure Performance scenarios - Instruments - Logging - Quartz Debug (OS X)

Slide 7

Slide 7 text

CPU Performance Optimization

Slide 8

Slide 8 text

- Unhappy users CPU CPU Tasks Optimization

Slide 9

Slide 9 text

- Unhappy users - System can abort your app CPU CPU Tasks Optimization

Slide 10

Slide 10 text

Time Profiler Demo CPU Tasks Optimization

Slide 11

Slide 11 text

CPU Tasks Optimization

Slide 12

Slide 12 text

CPU Tasks Optimization

Slide 13

Slide 13 text

- do less work - do work later - do slow in background and use placeholders - do work faster Main strategies CPU Tasks Optimization

Slide 14

Slide 14 text

Memory Performance Optimization

Slide 15

Slide 15 text

- Crashes => Unhappy Users Memory Memory Optimization

Slide 16

Slide 16 text

Allocations & Leaks Demo Memory Optimization

Slide 17

Slide 17 text

Memory Optimization

Slide 18

Slide 18 text

Memory Optimization

Slide 19

Slide 19 text

Memory Optimization

Slide 20

Slide 20 text

- do less work - do work later - break down work to smallest batches - use ARC :) - @autoreleasepool Main strategies Memory Optimization

Slide 21

Slide 21 text

.nib loading Tips and Tricks x10 faster

Slide 22

Slide 22 text

ARC vs MMM Tips and Tricks - (void)getPoints:(DPoint[2])outPoint forCenterPoint:(DPoint)centerPoint targetingVector: (DVector)targetingVector skipEquation:(BOOL)skip lineWidth:(DFloat)lineWidth { DVector normVector = DVectorNormalVector(targetingVector); DFloat originX = centerPoint.x + (lineWidth / 2.0f) * normVector.x; ... // some code outPoint[1] = (DPoint){originX, originY}; }

Slide 23

Slide 23 text

ARC vs MMM Tips and Tricks x5 faster on MMM - (void)getPoints:(DPoint[2])outPoint forCenterPoint:(DPoint)centerPoint targetingVector: (DVector)targetingVector skipEquation:(BOOL)skip lineWidth:(DFloat)lineWidth { DVector normVector = DVectorNormalVector(targetingVector); DFloat originX = centerPoint.x + (lineWidth / 2.0f) * normVector.x; ... // some code outPoint[1] = (DPoint){originX, originY}; }

Slide 24

Slide 24 text

Universal solutions Tips and Tricks [self.array addObject:[NSValue valueWithCGPoint:point]] xxx times faster VS @interface DPointsCollection : NSObject - (void)addPoint:(CGPoint)point atIndex:(NSUInteger)index; - (void)removePointAtIndex:(NSUInteger)index; ... @end

Slide 25

Slide 25 text

Sorted NSArray Tips and Tricks [self.array addObject:object]; [self.array sortUsing...];

Slide 26

Slide 26 text

Sorted NSArray Tips and Tricks NSUInteger index = [self.array indexOfObject:object inSortedRange:range options:NSBinarySearchingInsertionIndex usingComparator:comparator]; [self.array insertObject:object atIndex:index];

Slide 27

Slide 27 text

Delay large tasks Tips and Tricks - (void)addPerson:(DPerson*)person { ... [self save]; // large task } - (void)addBook:(DBook*)book { ... [self save]; // large task }

Slide 28

Slide 28 text

Delay large tasks Tips and Tricks - (void)addPerson:(DPerson*)person { ... [self delayedSave]; } - (void)addBook:(DBook*)book { ... [self delayedSave]; } - (void)delayedSave { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(save) object:nil]; [self performSelector:@selector(save) withObject:nil afterDelay:0.1f]; }

Slide 29

Slide 29 text

API Levels Tips and Tricks - try high level API first - then try lower level NSArray => CFArray => void* NSXMLParser => libxml

Slide 30

Slide 30 text

Questions & Answers Performance Optimization