mobile performance tuning: poor man's tips and tricks

31
Mobile performance tuning: poor man’s tips and tricks Mantas Puida / Unity iOS

Upload: valentin-simonov

Post on 16-Aug-2015

730 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Mobile Performance Tuning: Poor Man's Tips And Tricks

Mobile performance tuning: poor man’s tips and tricks

Mantas Puida / Unity iOS

Page 2: Mobile Performance Tuning: Poor Man's Tips And Tricks
Page 3: Mobile Performance Tuning: Poor Man's Tips And Tricks

Maybe it is too pretty? :)

Page 4: Mobile Performance Tuning: Poor Man's Tips And Tricks

Why this happens?

•Many people perceive <20 fps as bad performance

•60 fps = 16.7 ms / frame, 30 fps = 33.3 ms / frame, 20 fps = 50.0 ms / frame

•Rendering at some point is synced with LCD

•CPU is working too long•or… GPU is working too long

Page 5: Mobile Performance Tuning: Poor Man's Tips And Tricks

Two most common problems: exhausted fill rate or too much geometry

Page 6: Mobile Performance Tuning: Poor Man's Tips And Tricks

Or too much moving geometry, but let’s talk about bit later

Page 7: Mobile Performance Tuning: Poor Man's Tips And Tricks

Poor man’s explanation of the things

•Fill rate - how many pixels you can draw per second*

•Triangle throughput - how many triangles you can process per second*

*- in reality things are bit more complicated

Page 8: Mobile Performance Tuning: Poor Man's Tips And Tricks

Some school* grade math: iPhone 5s

•Fill rate: 3304 Mtex/s, Triangle t.: 68Mtri/s•Screen resolution: 1136x640•Can fill screen X times running @ 60 fps: X = 3304000000 / (60*1136*640) = 75.7 (lots of overdraw)

•Can handle Y static triangles running @ 60 fps: Y = 68000000/60 = 1.1 Mtris

*- most of my students fail this test

Page 9: Mobile Performance Tuning: Poor Man's Tips And Tricks

Some school grade math: iPhone 4*

•Fill rate: 400 Mtex/s, Triangle t.: 14Mtri/s•Screen resolution: 960x640•Can fill screen X times running @ 60 fps: X = 400000000 / (60*960*640) = 10.8 (not good)

•Can handle Y static triangles running @ 60 fps: Y = 14000000/60 = 0.2 Mtris

*- don’t trust much numbers you find on internet

Page 10: Mobile Performance Tuning: Poor Man's Tips And Tricks

How should I know if I’m GPU bound?Xcode 5 + iOS 7 (Debug Navigator)!

Page 11: Mobile Performance Tuning: Poor Man's Tips And Tricks

Practical measurement•iPhone 5s - up 55 layers of full screen transp. (75 theoretical) still allow 60 fps / 31 layer with Diffuse shader

• iPhone 4 - only 8 layers of full screen transp. (10 theoretical) still allow 60 fps / 1.6 layer with Diffuse shader

Advice #1: always measure what are device limits with your own setup of things. Start with lowest spec device first.Advice #2: use simple and effective shaders when possible

Page 12: Mobile Performance Tuning: Poor Man's Tips And Tricks

Tran

spar

ent f

ull s

cree

n la

yers

0

12.5

25

37.5

50

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

30

10.8

21.6

50

44

9.48

Page 13: Mobile Performance Tuning: Poor Man's Tips And Tricks

Switching from transparent to opaque

•iPhone 5s - up to 320 layers of full screen opaque still allow 60 fps

•iPhone 4 - 41 layer of full screen opaque still allow 60 fps

Advice #3: use opaque (non-transparent) shaders when possible

Page 14: Mobile Performance Tuning: Poor Man's Tips And Tricks

Opa

que

full

scre

en la

yers

0

100

200

300

400

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

7569

172

317278

41.4

Page 15: Mobile Performance Tuning: Poor Man's Tips And Tricks

Dynamic content•2D sprites: makes quite some pressure on GLES driver, which means higher CPU usage. Also could result in high overdraw, which also makes pressure on GPU too.

•3D animations: makes quite some pressure on CPU, maybe less pressure on GPU (unless expensive shaders)

Page 16: Mobile Performance Tuning: Poor Man's Tips And Tricks

Dynamic 2D content•iPhone 5S - 578 sprites, iPhone 4 - 113 sprites (square mesh 36 spr. / GPU bound) and still maintaining 60 fps.

Page 17: Mobile Performance Tuning: Poor Man's Tips And Tricks

2D S

prite

s

0

150

300

450

600

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

372

284298

578

439

113

Page 18: Mobile Performance Tuning: Poor Man's Tips And Tricks

iPhone 4: tight 2D mesh vs full rect

Page 19: Mobile Performance Tuning: Poor Man's Tips And Tricks

Tons of objects = bad•Lots of separate objects makes great pressure on GLES driver.

•Dynamic and static batching to the rescue! (Player Settings tab in Unity)

Advice #4: few bigger objects is better than lots of small objects

Page 20: Mobile Performance Tuning: Poor Man's Tips And Tricks

Dynamic 3D content•iPhone 5S - 309 low poly (384 pol.) CPU skinned meshes / 160 low poly GPU skinned meshes, iPhone 4 - 55 low poly CPU skinned meshes and still maintaining 60 fps. CPU skinning bounded by CPU performance, GPU skinning (GLES 3.0 only) bounded by GPU perf.

Page 21: Mobile Performance Tuning: Poor Man's Tips And Tricks

Disabling tangents•iPhone 5S - 318 characters with CPU skinning / 202 characters with GPU skinning,

• iPhone 4 - still 55 characters (draw call bound).

Advice #5: Keep amount of dynamic geometry (and skinned data) low.

Page 22: Mobile Performance Tuning: Poor Man's Tips And Tricks

Low

pol

y an

imat

ed c

hara

cter

s

0

100

200

300

400

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

303

118123

318

200

55

Page 23: Mobile Performance Tuning: Poor Man's Tips And Tricks

Switching to big objects•iPhone 5S - 122 characters (5K polies) with CPU skinning / 26 characters with GPU skinning,

• iPhone 4 - 18 characters.

Page 24: Mobile Performance Tuning: Poor Man's Tips And Tricks

Med

ium

siz

e (5

K po

l.) a

nim

ated

cha

ract

ers

0

35

70

105

140

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

119

3840

122

70

18.9

Page 25: Mobile Performance Tuning: Poor Man's Tips And Tricks

Dynamic 3D content•iPhone 5S - handles 90-400K moving polygons @ 60 fps (having less, but more detailed characters allows higher throughput)

• iPhone 4 - handles 20-90 K moving polygons @ 60 fps.

Page 26: Mobile Performance Tuning: Poor Man's Tips And Tricks

Anim

ated

pol

ygon

cou

nt (K

Tris

)

0

150

300

450

600

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

584

186198

596

343

92

Page 27: Mobile Performance Tuning: Poor Man's Tips And Tricks

Practical measurement: static content

• iPhone 5S - easily handles ~1.1 M static polygons @ 60 fps

• iPhone 4 - handles ~270 K static polygons @ 60 fps.

•Good match with other synthetic tests

Page 28: Mobile Performance Tuning: Poor Man's Tips And Tricks

Stat

ic p

olyg

on c

ount

(K T

ris)

0

300

600

900

1200

iPhone

4

iPhone

5

iPhone

5S

iPad M

ini 1

iPad 3

iPad Air

845

657597

1 1161 113

276

Page 29: Mobile Performance Tuning: Poor Man's Tips And Tricks

Summary•Don't trust numbers on the internet, profile in your environment. Small details matter.

•Profile worst and best devices. Estimate budgets for transparent and dynamic geometry.

•Use Xcode to figure out if you are CPU or GPU bound.•Large portions of screen covering transparent objects (or with expensive shaders) make you GPU bound.

•Lots of objects, dynamic geometry makes you CPU bound.

Page 30: Mobile Performance Tuning: Poor Man's Tips And Tricks

•Use tight meshes for transparent 2D stuff.•Use non-transparent shaders when possible.•Minimize amount of skinnable data (drop tangents when not needed).

•Lowering target framerate to 30-20 fps increases budgets 2x-3x.

•Need tons of small characters? 2D is less challenging (but you should care about details)

Page 31: Mobile Performance Tuning: Poor Man's Tips And Tricks

Resources from Unity Asset Store

•Unity Chan•Low Poly Micro Monster Pack•Primitives•2d CHARACTERS sprite package