extreme web performance for mobile devices

164
extreme web performance for mobile devices maximiliano @rtman rt.mobi

Upload: maximiliano-firtman

Post on 08-Sep-2014

6.876 views

Category:

Software


0 download

DESCRIPTION

Conference at Velocity Santa Clarar 2014

TRANSCRIPT

Page 1: Extreme Web Performance for Mobile Devices

extreme web performance for mobile devices

maximiliano @firtman firt.mobi

Page 2: Extreme Web Performance for Mobile Devices
Page 3: Extreme Web Performance for Mobile Devices
Page 4: Extreme Web Performance for Mobile Devices
Page 5: Extreme Web Performance for Mobile Devices

Slides, links and tests firt.mobi/velocity

Page 6: Extreme Web Performance for Mobile Devices

questions

yes, please !

QA at the end

Page 7: Extreme Web Performance for Mobile Devices

performance + mobile + web

1- Mobile Web today 2- Performance & Mobile 3- Tools 4- Initial loading & perception 5- Responsiveness & experience

Page 8: Extreme Web Performance for Mobile Devices
Page 9: Extreme Web Performance for Mobile Devices

1- mobile web today*

*today: june 2014

Page 10: Extreme Web Performance for Mobile Devices

1- mobile web today

- Web Platforms - The problem of Android - Webapps

Page 11: Extreme Web Performance for Mobile Devices

web platforms

Page 12: Extreme Web Performance for Mobile Devices

iOS and Android

web platforms

Page 13: Extreme Web Performance for Mobile Devices

Adobe Digital Index NetMarketShare Akamai.io Wikimedia Stats StatCounter

web platformsLinks at firt.mobi/velocity

Page 14: Extreme Web Performance for Mobile Devices

web platformsOthers

4%

Windows Phone 3%

Opera 5%

iOS!50%

Android!38%

Page 15: Extreme Web Performance for Mobile Devices

web platformsOthers

4%

Windows Phone 3%

Opera 5%

iOS!50%

Android!38%

Others?

• Firefox • UC Browser • Nokia Browser • BlackBerry Browser

Page 16: Extreme Web Performance for Mobile Devices

web platforms

iOS!50%

Safari!100%

Page 17: Extreme Web Performance for Mobile Devices

web platforms

iOS!50%

6.x!11%

7.x!89%

Source: Apple

Page 18: Extreme Web Performance for Mobile Devices

web platforms

Safari iOS6 5%

Safari iOS7!45%

Android!38%

Page 19: Extreme Web Performance for Mobile Devices

web platforms

Android!38%

Page 20: Extreme Web Performance for Mobile Devices

web platforms

Android!38%

Browser!64%

Chrome!36%

Page 21: Extreme Web Performance for Mobile Devices

web platforms

Page 22: Extreme Web Performance for Mobile Devices

web platforms

Page 23: Extreme Web Performance for Mobile Devices

web platforms

Android!38%

Samsung!32%

Browser!32%

Chrome!36%

Page 24: Extreme Web Performance for Mobile Devices

web platforms

Android!38%

4.4

4.1-4.3

4.0

2.3

Source: Android Dashboard

Page 25: Extreme Web Performance for Mobile Devices

web platformsOthers

4%

Windows Phone 3%

Opera 5%

iOS!50%

Android!38%

Page 26: Extreme Web Performance for Mobile Devices

web platforms

Samsung!12%

Android!12%

Others 4%

Windows Phone 3%

Opera 5%

Safari iOS6 5%

Safari iOS7!45%

Chrome!14%

Others?

• Firefox • UC Browser • Nokia Browser • BlackBerry Browser

Page 27: Extreme Web Performance for Mobile Devices

in a month… new phone

Page 28: Extreme Web Performance for Mobile Devices

future

Page 29: Extreme Web Performance for Mobile Devices

future

Page 30: Extreme Web Performance for Mobile Devices

future

Page 31: Extreme Web Performance for Mobile Devices

future

Page 32: Extreme Web Performance for Mobile Devices

it’s not just about browsers

Page 33: Extreme Web Performance for Mobile Devices

webapps

Page 34: Extreme Web Performance for Mobile Devices

full screen webapps

home screen webapps

webapps are also known as(

)

Page 35: Extreme Web Performance for Mobile Devices

webapps

Browser’s engine!

1- Web.app (~Safari) on iOS 2- Chrome on Android 3- Firefox on Android and FxOS

Page 36: Extreme Web Performance for Mobile Devices

webapps

native webapps

Page 37: Extreme Web Performance for Mobile Devices

hybrid apps

packaged webapps

native webapps are also known as(

)

Page 38: Extreme Web Performance for Mobile Devices

webapps

Web View

Page 39: Extreme Web Performance for Mobile Devices

webapps

Web View on iOS!

1- UIWebView on iOS 7 2- WKWebView on iOS 8

Page 40: Extreme Web Performance for Mobile Devices

webapps

Web View on Android!

1- WebKit from 2.x to 4.3 2- Chromium 30 on 4.4 3- Chromium on Samsung 4- Chromium on Fire OS

Page 41: Extreme Web Performance for Mobile Devices

webapps

Web View on Windows!

1- IE 10 on Windows (Phone) 8 2- IE 11 on Windows (Phone) 8.1

Page 42: Extreme Web Performance for Mobile Devices

1- mobile web today- Understand the real ecosystem - Android browsers - Don’t think you are an average user - Webapp solutions - May change future

Page 43: Extreme Web Performance for Mobile Devices

2- mobile & performance- Perception - Differences - Cellular networks - Responsive Web Design - Some data

Page 44: Extreme Web Performance for Mobile Devices

immediate feedback 100ms

!

perception

Jakob Nielsen - Usability Engineering

Page 45: Extreme Web Performance for Mobile Devices

immediate feedback 100ms

losing user’s flow of thoughts 1s

perception

Jakob Nielsen - Usability Engineering

Page 46: Extreme Web Performance for Mobile Devices

500ms delay, +26% user’s frustration

perception

Source: Radware

Page 47: Extreme Web Performance for Mobile Devices

“page slowdowns negatively affected

people’s long-term impression of the

entire brand”

perception

Source: Radware

Page 48: Extreme Web Performance for Mobile Devices

why do we need special care on mobile?

Page 49: Extreme Web Performance for Mobile Devices

CPU and GPU

Memory

differences

Page 50: Extreme Web Performance for Mobile Devices

CPU and GPU

Memory

differences

5x

Page 51: Extreme Web Performance for Mobile Devices

Wifi

differences

Page 52: Extreme Web Performance for Mobile Devices

Wifi, public spaces?

differences

Page 53: Extreme Web Performance for Mobile Devices

Cellular connections

differences

Page 54: Extreme Web Performance for Mobile Devices

We have 4G! We don't need to worry about performance...

(

)

Page 55: Extreme Web Performance for Mobile Devices

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

Only 2.2% is on 4G globally

Page 56: Extreme Web Performance for Mobile Devices

cellular

0

25

50

75

100

US Western Europe Asia Global

4G 2G/3G

~40% of the time 4G was not used

Page 57: Extreme Web Performance for Mobile Devices

Real Bandwidth (Mbps)cellular networks

0 2 4 6 8

2G 3G Wifi 4G

Page 58: Extreme Web Performance for Mobile Devices

RTT - latencycellular networks

2G

3G

4G

Home

0 250 500 750 1000

Min Max

Page 59: Extreme Web Performance for Mobile Devices

latency

request

bandwidth

Page 60: Extreme Web Performance for Mobile Devices

responsive web design

Page 61: Extreme Web Performance for Mobile Devices
Page 62: Extreme Web Performance for Mobile Devices

Responsive Web Design is a TOOL

Page 63: Extreme Web Performance for Mobile Devices

Responsive Web Design is NOT a GOAL

Page 64: Extreme Web Performance for Mobile Devices

Users DON’T care if your site is RESPONSIVE

(in terms of RWD)

Page 65: Extreme Web Performance for Mobile Devices

Users DO care if the site is FAST

Page 66: Extreme Web Performance for Mobile Devices

Page size

mobile vs desktop

responsive web design

Much smaller!6%

Slightly smaller!22%

Same Size!72%

Source: guypo.com

Page 67: Extreme Web Performance for Mobile Devices

Superbowl advertisers

mobile approach

responsive web design

Responsive site!50%

Desktop!7%

Mobile !43%

Source: blogs.keynote.com

Page 68: Extreme Web Performance for Mobile Devices
Page 69: Extreme Web Performance for Mobile Devices
Page 70: Extreme Web Performance for Mobile Devices

2- mobile and performance- Perception: 1s threshold - RTT latency - Test on low hardware and 2G/3G - Responsive Web Design !

Page 71: Extreme Web Performance for Mobile Devices

3- tools

Page 72: Extreme Web Performance for Mobile Devices

3- tools- where - measuring loading times - measuring responsiveness - online tools - html5 apis

Page 73: Extreme Web Performance for Mobile Devices

Simulator & Emulator

Real device

where

Page 74: Extreme Web Performance for Mobile Devices

emulators

Samsung!12%

Android!12%

Others!4%

Windows Phone 3%

Opera 5%

Safari iOS6 5%

Safari iOS7!45%

Chrome!14%

Page 75: Extreme Web Performance for Mobile Devices

emulators

Samsung!12%

Android!12%

Others!4%

Windows Phone!3%

Opera 5%

Safari iOS6 5%

Safari iOS7!45%

Chrome!14%

Page 76: Extreme Web Performance for Mobile Devices

emulators

Samsung!12%

Android!12%

Others!4%

Windows Phone 3%

Opera 5%

Safari iOS6 5%

Safari iOS7!45%

Chrome!14%

Page 77: Extreme Web Performance for Mobile Devices

DEMO

Page 78: Extreme Web Performance for Mobile Devices

online tools

Page 79: Extreme Web Performance for Mobile Devices

online tools

Page 80: Extreme Web Performance for Mobile Devices

remote inspectors

Page 81: Extreme Web Performance for Mobile Devices

remote inspectors

Samsung!12%

Android!12%

Others!4%

Windows Phone!3%

Opera 5%

Safari iOS6 5%

Safari iOS7!45%

Chrome!14%

Page 82: Extreme Web Performance for Mobile Devices

Measuring

DEMO

Page 83: Extreme Web Performance for Mobile Devices

Proxies / Network sniffers

• Charles Proxy • Fiddler

tools

Image from telerik fiddler

Page 84: Extreme Web Performance for Mobile Devices

Connection simulators• Charles Proxy • Clumsy for Windows • Network link conditioner from Xcode • Net Limiter for Windows • SlowyApp for Mac

tools

Page 85: Extreme Web Performance for Mobile Devices

Navigation Timing API

• window.performance • Timestamps available

html5 apis

Page 86: Extreme Web Performance for Mobile Devices

navigation timing api

Samsung!12%

Android!12%

Others!4%

Windows Phone!3%

Opera 5%

Safari iOS6!5%

Safari iOS7!45%

Chrome!14%

Page 87: Extreme Web Performance for Mobile Devices
Page 88: Extreme Web Performance for Mobile Devices

Navigation Timing APIhtml5 apis

DEMO

Page 89: Extreme Web Performance for Mobile Devices

Resource Timing API• Information per resource

html5 apis

Page 90: Extreme Web Performance for Mobile Devices

resource timing api

Samsung!12%

Android!12%

Others!4%

Windows Phone!3%

Opera 5%

Safari iOS6!5%

Safari iOS7!45%

Chrome!14%

Page 91: Extreme Web Performance for Mobile Devices

3- tools

- Learn where to test - Measure loading times - Measure responsiveness - HTML5 APIs !

Page 92: Extreme Web Performance for Mobile Devices

4- initial loading & perception

Page 93: Extreme Web Performance for Mobile Devices

4- initial loading & perception- 1 second threshold - classic checklist - ATF and the rest - responsive web design - future visits

Page 94: Extreme Web Performance for Mobile Devices
Page 95: Extreme Web Performance for Mobile Devices
Page 96: Extreme Web Performance for Mobile Devices
Page 97: Extreme Web Performance for Mobile Devices
Page 98: Extreme Web Performance for Mobile Devices

Image from developers.google.com

Page 99: Extreme Web Performance for Mobile Devices
Page 100: Extreme Web Performance for Mobile Devices

What!!? Do you expect a page load in 200ms?

(

)

Page 101: Extreme Web Performance for Mobile Devices

No really, we just need the PERCEPTION

of 1s

Page 102: Extreme Web Performance for Mobile Devices

Redirects

• From 150 to 1000 ms per redirect • mydomain.com -> m.mydomain.com • URL shorteners

Page 103: Extreme Web Performance for Mobile Devices

Redirections

DEMO

Page 104: Extreme Web Performance for Mobile Devices

Redirections

• From 1 to 5s !

Page 105: Extreme Web Performance for Mobile Devices
Page 106: Extreme Web Performance for Mobile Devices

idontwantyourfuckingapp.tumblr.com

Page 107: Extreme Web Performance for Mobile Devices

Compress resources

• Use Gzip in HTTP • For text-based files only

Page 108: Extreme Web Performance for Mobile Devices

Basic browser behavior

• Network Fetch • Parsing • Rendering

Page 109: Extreme Web Performance for Mobile Devices

Basic browser behavior

HTML

JS CSS

Page 110: Extreme Web Performance for Mobile Devices

Basic browser behavior

HTML

JS CSSBLOCKS PARSING BLOCKS RENDERING

Page 111: Extreme Web Performance for Mobile Devices

The 14K limit

Page 112: Extreme Web Performance for Mobile Devices

The 14K limit

• TCP slow start • Initial congestion window: ~14.6Kb (compressed) • > 14Kb will create another roundtrip

Page 113: Extreme Web Performance for Mobile Devices

We need to separate AVOBE THE FOLD

(ATF) content

Page 114: Extreme Web Performance for Mobile Devices

ATF in 1s = 1 RTT ~ < 14Kb ATF

Page 115: Extreme Web Performance for Mobile Devices

Data URI in CSS

• Images are non-blocking by default • Using Data URI in CSS creates blocking images • Use them only on non-ATF external CSS

ATF

Page 116: Extreme Web Performance for Mobile Devices

Client side rendering

• Careful with client-side frameworks • Try to render the initial view server-side • Render at least a basic view

ATF

Page 117: Extreme Web Performance for Mobile Devices

Client side rendering

• Careful with client-side frameworks • Try to render the initial view server-side • Render at least a basic view

ATF

5x

Page 118: Extreme Web Performance for Mobile Devices

Use illusion tricks

• Loading content animation • Minimal-ui viewport ASAP (iOS 7.1+) • Remember to keep the user engaged in 1s

ATF

Page 119: Extreme Web Performance for Mobile Devices

Web Fonts

• Blocks text rendering • Fonts are bigger than 14Kb • Use them with care • Remove characters

ATF

Page 120: Extreme Web Performance for Mobile Devices

Responsive Web Design

Page 121: Extreme Web Performance for Mobile Devices

Responsive Web Design

ATF on mobile is not the same as on desktop

Page 122: Extreme Web Performance for Mobile Devices

RWD

Page 123: Extreme Web Performance for Mobile Devices

RWD

Page 124: Extreme Web Performance for Mobile Devices

RWD

Page 125: Extreme Web Performance for Mobile Devices

RWD

not how it works by default

Page 126: Extreme Web Performance for Mobile Devices

RWD

Page 127: Extreme Web Performance for Mobile Devices

RWD

Page 128: Extreme Web Performance for Mobile Devices

RWD

Page 129: Extreme Web Performance for Mobile Devices

DON’T rely on RESPONSIVE WEB DESIGN

for first view

Page 130: Extreme Web Performance for Mobile Devices

RESPONSIVE WEB DESIGN is the future

Page 131: Extreme Web Performance for Mobile Devices

We are not saying go m.*

Page 132: Extreme Web Performance for Mobile Devices

Responsive Web Design

• Using same URL for mobile/desktop still a good a idea • Mix it with RESS / adaptive web design • Load media queries CSS async • Use server-side libraries • WURFL or DeviceAtlas

Page 133: Extreme Web Performance for Mobile Devices

After ATF is ready

• Load rest of your content • Use ATF experience: current performance, screen density, bandwidth • Make decisions: HD/SD

Page 134: Extreme Web Performance for Mobile Devices

Async scripts

<script async src=""></script> HTML5

Page 135: Extreme Web Performance for Mobile Devices

Defer non-ATF CSS

• No defer or async attributes (yet) • Inject <link> after rendering • load, requestAnimationFrame

Page 136: Extreme Web Performance for Mobile Devices

Speed future visits

• Be cache friendly • Use Application Cache for ATF content • Create a custom cache

Page 137: Extreme Web Performance for Mobile Devices

4- initial loading & perception

- ATF in 1s (illusion) - No redirects, GZip, no scripts - Only ATF CSS, careful with fonts - Defer anything else !

Page 138: Extreme Web Performance for Mobile Devices

5- responsiveness & experience

Page 139: Extreme Web Performance for Mobile Devices

4- responsiveness & experience

- consistent frame rate - immediate feedback - scrolling - your new enemy

Page 140: Extreme Web Performance for Mobile Devices

Keep framerate high and consistent

• Main UI thread as free as possible • Avoid repainting (software bitmap calculations)

consistent fps

Page 141: Extreme Web Performance for Mobile Devices

JavaScriptframerate

• Avoid DOM manipulations inside loops/scroll

var e = document.querySelector("#test");for (var i=0; i<100; i++) { // change e attributes });

JAVASCRIPT

Page 142: Extreme Web Performance for Mobile Devices

CSSframerate

• Promote GPU layers smartly selector {

-webkit-transform: translateZ(0); -webkit-perspective: 1000; } !

selector { z-index: 10; }

CSS

Page 143: Extreme Web Performance for Mobile Devices

Animationsframerate

• Don’t animate from JavaScript for basic stuff • Use requestAnimationFrame

Page 144: Extreme Web Performance for Mobile Devices

remember 100ms immediate feedback?

Page 145: Extreme Web Performance for Mobile Devices

Immediate feedback

• The 300ms delay !

• fixed viewport • FastClick solution

Page 146: Extreme Web Performance for Mobile Devices

Storage for immediate feedback

• web storage vs web sql vs indexeddb • Finally IndexedDB on iOS 8!

Page 147: Extreme Web Performance for Mobile Devices

navigator.geolocation .getCurrentPosition(cbOK, cbKO, { maximumAge: 60000 });

JAVASCRIPT

Geolocation cache

Page 148: Extreme Web Performance for Mobile Devices

Distract the user

Page 149: Extreme Web Performance for Mobile Devices

Scrolling

Page 150: Extreme Web Performance for Mobile Devices

Scrolling

• avoid re-painting • use touch overflow for momentum • don’t use JavaScript scrollers • on large scrolling areas: copy native

Page 151: Extreme Web Performance for Mobile Devices

Large scrolling areas

Let’s copy native frameworks: • iOS: UITableView • Android: ListView & Adapters

Page 152: Extreme Web Performance for Mobile Devices

Large scrolling areas

• Object pool !

Page 153: Extreme Web Performance for Mobile Devices

Infinite scroll

• DOM vs. iframe vs. object pool • on iOS 8 new API (caution: on beta)

Page 154: Extreme Web Performance for Mobile Devices

Your new enemy

Page 155: Extreme Web Performance for Mobile Devices

NOT THE USER

Page 156: Extreme Web Performance for Mobile Devices

YOUR DESIGNER

Page 157: Extreme Web Performance for Mobile Devices

Careful with some design features

• GPU vs CPU repaint • Important on scroll, transitions & animations

Page 158: Extreme Web Performance for Mobile Devices

Careful with some design features

• Transforms: translate, scale, rotate and opacity GPU • border-radius, gradients, shadows, filters CPU repaint

Page 159: Extreme Web Performance for Mobile Devices

5- responsiveness & experience- 100s feedback - Consistent fps - Avoid CPU repaints - Embrace GPU smartly - Profile & test !

Page 160: Extreme Web Performance for Mobile Devices

Picture from Simon Howden freedigitalphotos.net!

Picture from Simon Howden freedigitalphotos.net!

uf! we've covered a lot!

Page 161: Extreme Web Performance for Mobile Devices

1- Mobile Web today 2- Mobile Performance 3- Tools 4- Initial load & perception 5- Responsiveness & experience

Page 162: Extreme Web Performance for Mobile Devices

Slides, links and tests firt.mobi/velocity

Page 163: Extreme Web Performance for Mobile Devices

final thoughts

- measure and profile - on real devices - be simple, be aggressive

Page 164: Extreme Web Performance for Mobile Devices

you can reach a good experience

Pictures)from)freedigitalphotos.net)

thank you!

twitter: @firt mobilexweb.com

firt.mobi/pmw

Book signing: Thu 10.45am