appforum 2014 boost hybrid app performance

52
TOP 10 WAYS TO: BOOST HYBRID APP PERFORMANCE ROB GALVIN

Upload: robgalvinjr

Post on 13-Jul-2015

66 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: AppForum 2014 Boost Hybrid App Performance

TOP 10 WAYS TO:BOOST HYBRID APP PERFORMANCEROB GALVIN

Page 2: AppForum 2014 Boost Hybrid App Performance

ME

ROB GALVIN

NORTH CAROLINA, USA

DATABASE, DESKTOP, WEB, MOBILE

RHOMOBILE, EMDK FOR ANDROID,

ENTERPRISE BROWSER

http://tiny.cc/robg

Page 3: AppForum 2014 Boost Hybrid App Performance

YOU & PERFORMANCE

Page 4: AppForum 2014 Boost Hybrid App Performance

ABOUT THIS PRESENTATION

Page 5: AppForum 2014 Boost Hybrid App Performance

SLOW

$.get("server/product.aspx?id=100").done(

function(page){

$("body").html(page);

});

<li><a href="server/product.aspx?id=100">TC55</a></li>

Page 6: AppForum 2014 Boost Hybrid App Performance

PROBLEM: ROUNDTRIPS TO SERVER TO GET UI AND DATA

TAPREQUEST

PAGEWAIT

GET

RESPONSE

DISPLAY

PAGE

Page 7: AppForum 2014 Boost Hybrid App Performance

DON’T GENERATE UI ON THE SERVER

#10

Page 8: AppForum 2014 Boost Hybrid App Performance

FAST

Create UI on client side in

Javascript

Insert/Remove views into DOM

as needed

SINGLE PAGE ARCHITECTURE

<html>

<head>

<title>Huge App</title>

<script src=”app.js”/>

</head>

<body>

</body>

</html>

Page 9: AppForum 2014 Boost Hybrid App Performance

SLOW

// Get Data

$.ajax({ url: "server/product.aspx?id=100"}).done(

function(product){

// some JSON structure

displayProduct(product);

});

Page 10: AppForum 2014 Boost Hybrid App Performance

PROBLEM: UI NON RESPONSIVE

TAPREQUEST

DATAWAIT

PARSE

DATA

DISPLAY

VIEW

Page 11: AppForum 2014 Boost Hybrid App Performance

MAKE SOMETHING HAPPEN IMMEDIATELY

DON’T LET USER WAIT FOR UI

# 9

Page 12: AppForum 2014 Boost Hybrid App Performance

FAST

TAPDISPLAY

VIEW

REQUEST

DATAWAIT

UPDATE

VIEW

displayView();

// Get Some Lookup Data

$.ajax({ url: "server/slowfeed"}).done( function(data){

updateView(data);

});

Page 13: AppForum 2014 Boost Hybrid App Performance

SLOW

// Get Some Lookup Data

$.ajax({ url: "server/shipping"}).done( function(data){

shipping = data;

});

Page 14: AppForum 2014 Boost Hybrid App Performance

PROBLEM: UNNECESSARY DELAY ON DATA THAT DOES NOT CHANGE OFTEN

Page 15: AppForum 2014 Boost Hybrid App Performance

CACHE STATIC / SEMI-STATIC DATA

# 8.1

Page 16: AppForum 2014 Boost Hybrid App Performance

FAST

Use RHOM to keep data local

Use RhoConnect to keep

‘semi-static’ data in sync with

differential updatesvar shipping = Shipping.find(‘all’);

Page 17: AppForum 2014 Boost Hybrid App Performance

SLOW

// Didn’t you say to do this in #9

displayView();

// Get Some Lookup Data

$.ajax({ url: "server/slowfeed"}).done( function(data){

updateView(data);

});

Page 18: AppForum 2014 Boost Hybrid App Performance

PROBLEM: EMPTY UI WHILE WAITING FOR DATA

Page 19: AppForum 2014 Boost Hybrid App Performance

CACHE DYNAMIC DATA

# 8.2

Page 20: AppForum 2014 Boost Hybrid App Performance

FAST

SHOW LAST KNOWN GOOD

DATA IS BETTER THAN

NOTHING AT ALL

// Show UI After Tap - Rule #9

displayView();

// Use RHOM for last known data

displayCachedOldData();

// Get Some Lookup Data

$.ajax({ url:

"server/slowfeed"}).done(

function(data){

showData(data);

});

Page 21: AppForum 2014 Boost Hybrid App Performance

SLOW

$(“#nav a.back”).on(“click”,clickhandler);

$(“#nav a.back”).css(“color”,”blue”);

$(“#nav a.back”).css(“text-decoration”,”none”);

$(“#nav a.back”).attr(“href”,”#”);

Page 22: AppForum 2014 Boost Hybrid App Performance

PROBLEM: UNNECESSARY DOM QUERIES

Page 23: AppForum 2014 Boost Hybrid App Performance

CACHE QUERY SELECTORS

# 8.3

Page 24: AppForum 2014 Boost Hybrid App Performance

FAST

var nextButton = $(“#nav a.next”);

nextButton.on(“click”,clickhandler);

nextButton.css(“color”,”blue”);

nextButton.css(“text-decoration”,”none”);

nextButton.attr(“href”,”#”);

Page 25: AppForum 2014 Boost Hybrid App Performance

ANIMATIONS

.page

.left

.page

.center

.page

.right

//Put next page to be display off viewport to right

$(“#page2”).attr(“class”,”page right”);

// Transition new page to viewport

$(“#page2”).attr(“class”,”page center transition”);

// Transition old page off viewport to the left

$(“#page1”).attr(“class”,”page left transition”);

Page 26: AppForum 2014 Boost Hybrid App Performance

SLOW

.page {

position:absolute; top:0, left:0, width:100%; height:100%

}

.page.left {

left: -100%;

}

.page.center {

left:0;

}

.page.right {

left: 100%;

}

.page.transition {

transition-duration: .25s;

}

Page 27: AppForum 2014 Boost Hybrid App Performance

PROBLEM: NOT USING GPU

Page 28: AppForum 2014 Boost Hybrid App Performance

HARDWARE ENABLE YOUR CSS

* WINDOWS MOBILE/CE = NO GPUDON’T USE ANIMATIONS

# 7

Page 29: AppForum 2014 Boost Hybrid App Performance

FAST.page {

position:absolute; top:0, left:0, width:100%; height:100%;

transform: translate3d(0,0,0);

}

.page.left {

transform: translate3d(-100%,0,0);

}

.page.center {

transform: translate3d(0,0,0);

}

.page.right {

transform: translate3d(100%,0,0);

}

.page.transition {

transition-duration: .25s;

}

Page 30: AppForum 2014 Boost Hybrid App Performance

SLOW

click: 308ms

click: 302ms

click: 305ms

Page 31: AppForum 2014 Boost Hybrid App Performance

PROBLEM: WEBVIEW WAITING FOR DOUBLE-TAP

Page 32: AppForum 2014 Boost Hybrid App Performance

AVOID 300MS CLICK EVENT DELAY

# 6

Page 33: AppForum 2014 Boost Hybrid App Performance

FAST

Use Touch Events?

Cons:

- Can’t use same code on desktop

- Extra conditioning

- May need Touch Start for gestures

touchStart: 5ms

click: 309ms

Use FastClick

https://github.com/ftlabs/fastclick

Micro Library

Don’t have to change your code

Page 34: AppForum 2014 Boost Hybrid App Performance

SLOW

<li><img src=”/images/icon_home”/>Home<li>

<li><img src=”/images/icon_gears”/>Settings<li>

<li><img src=”/images/icon_3dots”/>Details<li>

<li><img src=”/images/icon_camera”/>Take Picture<li>

<li><img src=”/images/icon_barcode”/>Scan Barcode<li>

Page 35: AppForum 2014 Boost Hybrid App Performance

PROBLEM: ALOT OF HTTP REQUESTS

Page 36: AppForum 2014 Boost Hybrid App Performance

* EVEN BETTER - USE ICON-FONTS

- Vector

- Scalable

- Pixel Perfect

- More Adaptable

- More CSS Control

USE SPRITES TO STORE IMAGES*

# 5 SPRITECOW.COM

Page 37: AppForum 2014 Boost Hybrid App Performance

SLOWcolor: rgb(230, 230, 230);

text-shadow: 0px -1px 0px rgba(30, 30, 30, 0.8);

-webkit-border-radius: 30px;

-moz-border-radius: 30px;

border-radius: 30px;

background: rgb(210, 20, 20);

background: -moz-linear-gradient(90deg, rgb(210, 20, 20)

30%, rgb(250, 20, 20) 70%);

background: -webkit-linear-gradient(90deg, rgb(210, 20,

20) 30%, rgb(250, 20, 20) 70%);

background: -o-linear-gradient(90deg, rgb(210, 20, 20)

30%, rgb(250, 20, 20) 70%);

background: -ms-linear-gradient(90deg, rgb(210, 20, 20)

30%, rgb(250, 20, 20) 70%);

background: linear-gradient(0deg, rgb(210, 20, 20) 30%,

rgb(250, 20, 20) 70%);

-webkit-box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.75);

-moz-box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.75);

box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.75);

Page 38: AppForum 2014 Boost Hybrid App Performance

SHADOWS AND GRADIENTS ARE PERFORMANCE

KILLERS

# 4

Page 39: AppForum 2014 Boost Hybrid App Performance

FAST

DON’T USE SHADOWS, GRADIENTS, ETC

KEEP UP WITH MODERN UI DESIGN

FLAT IS THE NEW BLACK

Page 40: AppForum 2014 Boost Hybrid App Performance

SLOW

$(‘body’).append(‘<ul id=”products”></ul>’);

for (var i = 1; i <100; i++){

$(‘#producs’).append(‘<li>’ + product[i] + ‘</li>’);

}

Page 41: AppForum 2014 Boost Hybrid App Performance

PROBLEM: TRIGGER REFLOW WHEN DOM IS TOUCHED

Page 42: AppForum 2014 Boost Hybrid App Performance

AVOID REFLOWS & KEEP DOM SHALLOW

# 3

Page 43: AppForum 2014 Boost Hybrid App Performance

FAST

var products = ‘<ul id=”products”>’;

for (var i = 1; i <100; i++){

products += ‘<li>’ + product[i] + ‘</li>’;

}

products += ‘</ul>’;

$(‘body’).append(products);

Page 44: AppForum 2014 Boost Hybrid App Performance

SLOW

<link rel="stylesheet" href="css/jquery.mobile-1.4.3.min.css"/>

<script src="js/jquery-1.11.1.min.js"></script>

// I NEED THIS BECAUSE I WANT MY PAGES TO HAVE TRANSITIONS<script src="js/jquery.mobile-1.4.3.min.js"></script>

Page 45: AppForum 2014 Boost Hybrid App Performance

PROBLEM: TOO MUCH EXTRA BAGGAGE FOR USE CASE

Page 46: AppForum 2014 Boost Hybrid App Performance

UNDERSTAND TRADEOFFS FOR FRAMEWORK USAGE

# 2

Page 47: AppForum 2014 Boost Hybrid App Performance

FAST

CONSIDER MICRO LIBRARIES

KNOW WHO IS DICTATING ARCHITECTURE

INSPECT LIBRARY FOR PERFORMANCE

PRACTICES

Page 48: AppForum 2014 Boost Hybrid App Performance

SLOW

Page 49: AppForum 2014 Boost Hybrid App Performance

PROBLEM: NOT TESTING REAL WORLD

Page 50: AppForum 2014 Boost Hybrid App Performance

TEST ON DEVICE - BECOME EXPERT IN TOOLS TO

MEASURE PERFORMANCE

# 1

Page 51: AppForum 2014 Boost Hybrid App Performance

SUMMARY

10. Don’t Generate the UI on the server

9. Display something while waiting for the data

8. Cache everything you can - use RHOM

7. GPU Enable your CSS

6. Avoid 300ms Click Delay

5. Use Font-Icons or Sprites for icons/images

4. Forget shadows/gradients - use modern flat UI design

3. Know your framework - weigh bang for buck!

2. Reflow = Jankiness - Avoid and eliminate them

1. Test with Many Devices - know your profiling tools

Page 52: AppForum 2014 Boost Hybrid App Performance