Slide 1

Slide 1 text

The Amazing Race: Performance of Standard iOS Elements and Technologies By Janina Kutyn

Slide 2

Slide 2 text

In this talk Text Rounded corners Shadows Layout

Slide 3

Slide 3 text

First, a little theory UIKit CoreAnimation CoreGraphics . . . Hardware

Slide 4

Slide 4 text

1001 ways to draw text

Slide 5

Slide 5 text

Text UILabel UITextView CATextLayer CoreText TextKit

Slide 6

Slide 6 text

1) UILabel

Slide 7

Slide 7 text

2) UITextView

Slide 8

Slide 8 text

3) CATextLayer

Slide 9

Slide 9 text

4) CoreText

Slide 10

Slide 10 text

5) TextKit https://github.com/KyoheiG3/AttributedLabel

Slide 11

Slide 11 text

TextKit, huh? https://www.raywenderlich.com/2257-text-kit-tutorial-getting-started

Slide 12

Slide 12 text

Measuring Performance Always test on device instead of the simulator! iPhone X, iOS 11 Repeat testing Find average result

Slide 13

Slide 13 text

Baseline UIView Time in Milliseconds 0 1 0,88

Slide 14

Slide 14 text

Execution time UITextView UILabel TextKit CATextLayer CoreText Time in Milliseconds 0 6 12 18 24 30 1,77 2,55 3,43 4,39 27,4

Slide 15

Slide 15 text

Execution time CATextLayer CATextLayer + View UILabel Time in Milliseconds 0 1 2 3 4 5 4,39 4,25 2,55

Slide 16

Slide 16 text

rounded corners: so basic

Slide 17

Slide 17 text

Rounded Corners CALayer + cornerRadius CALayer + mask CoreGraphics

Slide 18

Slide 18 text

1) CALayer

Slide 19

Slide 19 text

1b) CALayer

Slide 20

Slide 20 text

2) CALayer + Bezier Path

Slide 21

Slide 21 text

3) CoreGraphics

Slide 22

Slide 22 text

Execution time CoreGraphics CALayer + clipsToBounds CALayer + mask CALayer + masksToBounds Time in Milliseconds 0 1 2 3 1,41 1,66 1,91 2,4

Slide 23

Slide 23 text

Note: shouldRasterize

Slide 24

Slide 24 text

Execution time CALayer + masksToBounds + shouldRasterize Time in Milliseconds 0 1 2 3 2,3 1,41

Slide 25

Slide 25 text

shadows: so are they cool or not?!

Slide 26

Slide 26 text

Shadows CALayer CoreGraphics UIImage

Slide 27

Slide 27 text

1) CALayer

Slide 28

Slide 28 text

1b) CALayer + shadowPath

Slide 29

Slide 29 text

2) CoreGraphics

Slide 30

Slide 30 text

3) UIImage

Slide 31

Slide 31 text

Execution time UIImage CALayer CoreGraphics CALayer + shadowPath Time in Milliseconds 0 2 4 6 8 10 2,14 2,33 3,34 9,82

Slide 32

Slide 32 text

rounded corners + shadows: you think it’d be easy but it’s not

Slide 33

Slide 33 text

Rounded Corners + Shadows Shadow as UIView CAShapeLayer CoreGraphics

Slide 34

Slide 34 text

1) Shadow as UIView

Slide 35

Slide 35 text

2) CAShapeLayer

Slide 36

Slide 36 text

3) CoreGraphics

Slide 37

Slide 37 text

Execution time Subview CoreGraphics CAShapeLayer Time in Milliseconds 0 1 2 3 2,1 2,42 3,1

Slide 38

Slide 38 text

I’m noticing a trend… CALayer CoreGraphics UIKit

Slide 39

Slide 39 text

CoreGraphics Rounded Corners Shadow Rounded Corners + Shadow Time in Milliseconds 0 1 2 3 2,42 2,33 2,4

Slide 40

Slide 40 text

AutoLayout? more like AutoDELAYout

Slide 41

Slide 41 text

Layout AutoLayout UIStackView Manual

Slide 42

Slide 42 text

1) AutoLayout

Slide 43

Slide 43 text

2) UIStackView

Slide 44

Slide 44 text

3) Manual Layout

Slide 45

Slide 45 text

Execution time AutoLayout UIStackView Manual Layout AutoLayout iOS 12 Time in Milliseconds 0 2,8 5,6 8,4 11,2 14 6,65 1,7 12 14

Slide 46

Slide 46 text

Final Thoughts UIKit elements have overhead CoreGraphics vs CoreAnimation AutoLayout always slower than manual Up to you to choose what meets your needs

Slide 47

Slide 47 text

Thank you!