Mobile Performance Tuning: Poor Man's Tips And Tricks

Preview:

Citation preview

Mobile performance tuning: poor man’s tips and tricks

Mantas Puida / Unity iOS

Maybe it is too pretty? :)

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

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

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

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

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

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

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

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

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

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

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

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)

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

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

iPhone 4: tight 2D mesh vs full rect

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

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.

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.

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

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

• iPhone 4 - 18 characters.

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

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.

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

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

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

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.

•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)

Resources from Unity Asset Store

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

Recommended