Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Performance Optimization for iOS Apps

Performance Optimization for iOS Apps

Tips & Tricks from personal experience.

Vitalii Topoliuk

August 14, 2013
Tweet

More Decks by Vitalii Topoliuk

Other Decks in Programming

Transcript

  1. - Performance scenarios - How to measure performance - How

    to improve key scenarios - Tips and Tricks Contents:
  2. - Not just about speed - CPU tasks - Memory

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

    - Rendering - File I/O - Networking - Power Performance Performance scenarios
  4. Overall recommendations Performance scenarios - Don’t guess, just measure -

    Measure on slowest device - Measure on pessimistic data - Measure on real data
  5. - do less work - do work later - do

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

    down work to smallest batches - use ARC :) - @autoreleasepool Main strategies Memory Optimization
  7. 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}; }
  8. 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}; }
  9. 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
  10. Sorted NSArray Tips and Tricks NSUInteger index = [self.array indexOfObject:object

    inSortedRange:range options:NSBinarySearchingInsertionIndex usingComparator:comparator]; [self.array insertObject:object atIndex:index];
  11. Delay large tasks Tips and Tricks - (void)addPerson:(DPerson*)person { ...

    [self save]; // large task } - (void)addBook:(DBook*)book { ... [self save]; // large task }
  12. 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]; }
  13. API Levels Tips and Tricks - try high level API

    first - then try lower level NSArray => CFArray => void* NSXMLParser => libxml