Created
June 19, 2018 10:59
-
-
Save niwatako/b4c74f658ee0ed7d267d5c687313c29e to your computer and use it in GitHub Desktop.
High Performance Auto Layout #roppongiswift #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 佐藤さん(@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しない |
Author
niwatako
commented
Jun 19, 2018
- https://twitter.com/hatakenokakashi/status/1009035907595321349
- https://speakerdeck.com/satotakeshi/10fen-dezhen-rifan-ru-high-performance-auto-layout?slide=30
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment