tom germeau: mobile apps: finding the balance between performance and flexibility

44
EmpireJS 2012 Mobile Apps: Finding the balance between performance and flexibility Tom Germeau - @tomg chartbeat.com

Upload: chartbeat

Post on 09-May-2015

3.812 views

Category:

Technology


4 download

DESCRIPTION

EmpireJS 2012, New York City

TRANSCRIPT

Page 1: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

EmpireJS 2012Mobile Apps: Finding the balance between

performance and flexibility

Tom Germeau - @tomgchartbeat.com

Page 2: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

I DESIGN & ENGINEER AT CHARTBEAT

Hi. I’m Tom.

Page 3: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Joost2007 - 2009

STANDALONE JS/SVG BASED VIDEO PLAYERSAME CHALLENGE AS TODAY: KEEP UI SNAPPY

Page 4: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

ChartbeatREALTIME ANALYTICS. JS EVERYWHERE. DEMO!

Page 5: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

The goalA BETTER MOBILE DASHBOARD

Page 6: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

todo

Page 7: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Coming up ...Our constraints

Choosing a frameworkMaking it work

Layers & performanceOther Web tech

Page 8: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

5 weeksFROM MOCKUPS TO APPSTORE.

BUT HAVE OTHER PLATFORMS IN MIND.

Page 9: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

JS+Python ShopAND WE WANT TO KEEP THINGS SIMPLE

Page 10: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

HTML5/JS is so 2011AT LEAST THAT’S WHAT ZUCKERBERG SAID

* Our Biggest Mistake Was Betting Too Much On HTML5

Page 11: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

WHAT HE ACTUALLY MEANT ...

Page 12: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

The tool didn’t fit the job anymore

A CHANGE IN REQUIREMENTS MADEAN HTML ONLY APP INSUFFICIENT

Page 13: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Full native AppUNKNOWN & TOO ADVANCED

DIDN’T FIT THE JOB

Page 14: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

CordovaONE BLANK WEBVIEW.

DIDN’T FIT THE JOB.

Page 15: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Cocoa TouchEASILY HANDLE ADVANCEDGESTURES AND NAVIGATION

Page 16: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

HTML & JSFORMATTING AND STYLINGSCRIPTING INTERACTIONS

Page 17: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

HTML & JSDUH. REUSE LARGE AMOUNTS OF CODE/ASSETS

ON OTHER PLATFORMS

Page 18: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Thin native wrapperTHE SWEET SPOT: SCRIPTABLE VIEWDECK

WITH MULTIPLE WEBVIEWS

Page 19: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

ImplementationWE PICKED A PLATFORM

LET’S BUILD ON IT

Page 20: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

ViewDeck (open source)

NavigationController (cocoa)

UIWebView (cocoa)

Native Stack

*

*

Page 21: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Closure CompilerSANITY CHECK CODE &

PROVIDES SIMPLE MODULE SYSTEM

Page 22: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

UIWebView

/mobile/dashboard.html/js/v123-app.jsnew chartbeat.Dashboard()

UIWebView

/mobile/menu.html/js/v123-app.jsnew chartbeat.Menu()

UIWebView

/mobile/page.html/js/v123-app.jsnew chartbeat.Page()

App startup

UIWebView

/mobile/traffic.html/js/v123-app.jsnew chartbeat.Traffic()

dashboard ready

Page 23: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Scripting the wrapperCONFIGURING AND NAVIGATING

WEBVIEWS FROM JS

Page 24: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Scripting the wrapperchartbeat.mobile.exec('navigate', { 'target': 'left', 'url': '../menu/#state=loggedin’});// communicate using hashchangeevents

Page 25: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Managing renderingREALTIME DATA MAKES OUR DOM CHANGE CONSTANTLY

Page 26: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

One big LayerHA-BROWSERS WILL DIVIDE YOUR PAGE

IN ARBITRARY SQUARE TILES

Page 27: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Layersdiv { transform: translateZ(0); /* move div to own compositing layer * to hint heavily updated areas */}

Page 28: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

LayersUPDATE ASPECTS OF YOUR COMPOSITION

WITHOUT RUNNING LAYOUT AND RENDERERS

Page 29: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

LayersWATCH OUT FOR UNWANTED MODE SWITCHES

ANIMATED OPACITY, ADDING/REMOVING STYLES, ...

Page 30: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Filtersdiv { filter: hue-rotate(120deg); /* move div to own compositing layer */ /* not a lot of support yet */}

Page 31: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility
Page 32: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Zen of PerformanceMINIMUM LAYER COUNT VS MINIMUM REDRAWS

Page 33: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Zen of Performance MORE MEMORY, SMOOTHER EXPERIENCE,

EASIER TO CODE UNTIL YOU RUN OUT

Page 34: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Native Scroll-webkit-overflow-scrolling: touch;/* iOS5+ *//* <iOS4 fall back to Scrollability */

Page 35: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

SVG/CSS vs CanvasOR HOW WE BUILT

A BATTERY FRIENDLY GAUGE

Page 36: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

SVG/CSS vs Canvas

ONE DRAW. TONS OF REDRAWS. DEMO!

Page 37: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

SVG/CSS vs Canvasbackground: radial-gradient(...);mask: url(gauge.svg);transform-origin: center center;transform: rotate(-124deg);transition: all 1.5s ease

/* does not trigger redraw on animation */

Page 38: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

App lifecycleAPPS DON’T REALLY (ALWAYS) QUIT

Page 39: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Cheap SSL LoginJUST CREDENTIALS OVER CORS

Page 40: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Avoid getting ‘jetsammed’HANDLE IOS MEMORY PRESSURE NOTIFICATIONS

Page 41: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Avoid getting ‘jetsammed’BE ABLE TO CON/DESTRUCT YOUR VIEW

FROM YOUR MODEL AT ALL TIMES

Page 42: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

// iOS5 - Chromium 12[WebView _enableRemoteInspector]

// iOS6 - Safari 6// works out of the box!!

DevTools & Simulator

Page 43: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Thank youChartbeat.com/jobs

@tomg

Page 44: Tom Germeau: Mobile Apps: Finding the balance between performance and flexibility

Creditshttps://developers.google.com/closure/compiler/

http://nerds.airbnb.com/box-shadows-are-expensive-to-paint

http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome

http://www.html5rocks.com/en/tutorials/filters/understanding-css/

http://joehewitt.com/2011/10/05/fast-animation-with-ios-webkit

http://atnan.com/blog/2011/11/17/enabling-remote-debugging-via-private-apis-in-mobile-safari/

http://joehewitt.com/2011/10/05/fast-animation-with-ios-webkit