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

Tuning for Speed

Tuning for Speed

Chapter 12 of "iOS Core Animation" presented at Tumblr's iOS Book Club

Jasdev Singh

May 03, 2016
Tweet

More Decks by Jasdev Singh

Other Decks in Programming

Transcript

  1. CPU and GPU → GPU is optimized for the sort

    of highly parallel floating point math. → CPU can perform arbitrary computations.
  2. Stages of Core Animation → Layout: Prepare view/layer hierarchy and

    set up the properties of the layer. → Display: Backing images are drawn (drawRect(_:) or drawLayer(_:inContext:)) → Prepare: CD gets ready to send the animation data to the render server (Backboard). → Commit: Final phase where CA packages up and sends the layers and animation properties.
  3. Stages of Core Animation Cont. → Render server deserializes data

    to form render tree → For each frame of the animation: → Calculates the intermediate values for all of the layer properties → Renders the visible triangles to the screen (GPU)
  4. Factors that Slow Layer Drawing (GPU- Bound Operations) → Too

    much geometry → Too much overdraw--caused by overlapping semitransparent layers (finite fill-rate). → Offscreen drawing--occurs when an effect cannot be achieved by directly drawing onto the screen (rounded corners, layer masks, etc.) → Too-large images
  5. Factors that Slow Start of the Animation (CPU-Bound Operations) →

    Layout calculations for complex view hierarchies → Lazy view loading (e.g. loading from a nib file or Storyboard) → Core Graphics drawing (drawRect(_:)). Backing image is created in memory with the same size of the view. → Image decompression
  6. Testing → Always test on a device, the simulator won't

    give an accurate representation of performance. → Test with Release configurations to take advantage optimizations
  7. Instruments → Time Profiler → Core Animation → OpenGL ES

    Driver (used to debug GPU performance issues)
  8. Core Animation Instrument → FPS breakdown → Color blended layers

    (common source of overdraw) → Color hits green and misses red (when using shouldRasterize) → Color copied images (highlights images that have to be copied to the render server)
  9. Core Animation Instrument Cont. → Color immediately (draws debug colors

    immediately) → Color misaligned images (nonintegral coordinates) → Color offscreen-rendered yellow → Color OpenGL Fast Path Blue → Flash updates regions (redrawn content)