Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created June 19, 2018 10:59
Show Gist options
  • Save niwatako/b4c74f658ee0ed7d267d5c687313c29e to your computer and use it in GitHub Desktop.
Save niwatako/b4c74f658ee0ed7d267d5c687313c29e to your computer and use it in GitHub Desktop.
High Performance Auto Layout #roppongiswift #CodePiece
### 佐藤さん(@hatakenokakashi) High Performance Auto Layout
High Performance Auto Layoutというセッションを振り返ります。
MAMORIO株式会社でiOSエンジニアをしています。
High Performance Auto LayoutはiOS12でAutoLayoutのパフォーマンスが上がったことが紹介されている。
#### Independent Sibling Views
兄弟関係の、View間で関係のないView同士の描画パフォーマンスが改善された。
#### Dependent Sibling Views・Nested Veiws
相互に関係のある兄弟関係のView同士・ネストしたViewの描画が指数関数的にパフォーマンスが落ちるのが線形に
#### Performance Improvements in iOS12
Long Roe, Deep Hierarchy, Collection View, MovingTree, Hieralcy Remove
アップデートするだけでパフォーマンスが上がる。
#### Constraintのつけ外しはパフォーマンスが下がるので避けるべき。
updateConstraints
で deactivateしたり、removeAll()で消して新しくつけなおしたりとか。
成約を外してもう一度つけ直すとパフォーマンスが下がる。
updateConstraints() {
if self.constraints == nil {
// 制約をつける
}
}
このようにするとパフォーマンスが上がる。
#### The Render Loop
UpdateConstraintは一番末端の子Viewから制約を決めて親へたどっていく
レイアウトするときは親からレイアウトされて、ディスプレイするときは親から表示される。
#### Activating constraint - Internal Structure
レイアウトするときのエンジンがあって、そこが各ビューのサイズや位置を計算する。
Unknowns layout must calculate
minX minY width, heightが設定されているとき
text2.minX = text1.minX + text1.width + 20
こういう計算をさせるとパフォーマンスが下がる。
ConstraintをRemoveしたりするとこの計算が再度行われることになる。
#### Building Efficient Layout より効果的なレイアウト
Instruments に Auto Layout のパフォーマンスの測定が追加された。
どういう制約が設定されて時間がかかったか確認する事ができる。
#### Building More Performance Layout
Cell上に猫の画像がある場合ない場合
Constraintを付け替えたりするとパフォーマンスが落ちる。
Imageがアルバイトない場合のどちらにもConstraintをつけておく。
#### まとめ
- (すべての)制約を外すことを避ける’
- 一度だけ静的な制約をつける
- 必要なときだけ制約を変更する
- Viewを非表示に、不用意にRemoveしない
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment