High Performance Auto Layout

Posted by Den on June 15, 2018 · 5 mins read

High Performance Auto Layout

WWDC 2018

High Performance Auto Layout

WWDC 2018

updateConstraints()

DO NOT Removes & Adds constraint every time
Minimize update constraints

Render Loop

Render Loop

Activating a Constraint

Internal structure
Triggering the layout pass

layoutSubviews()

Copying data from engine to subView

Local vs Global Layout

Performance Scales

Model The Problem Naturally

  • Using constraints
  • Don’t wedge two layouts into one set of constraints
Don’t wedge

Error Minimization

Engine is not perfect. The engine try to minimize errors.

Minimize error

Performance Intuition

  • Don’t churn
  • Basic algebra
  • Engine is a layout cache and tracker
  • You pay for what you use

Building Efficient Layouts

Instruments for Layouts 👍
More Performance Layout
More Performance Layout

UIView.noIntrinsicMetric

To parent, 
“hey I already have my size, don’t bother to do the text measurement”

noIntrinsicMetric

System Layout Size Fitting Size

systemLayoutSizeFitting(_ targetSize:)

Unsatisfiable Constraints

  • There is no solution for the specified constraints
  • Logging will help you to debug
  • Can mask other issues
  • See related session for debugging tips