68
page 1 famous . @stevenewcomb Web App Performance the story of becoming famo.us beta signup www.famo.us

HTML5 DevConf Oct 2012 Tech Talk

  • Upload
    befamous

  • View
    19.749

  • Download
    2

Embed Size (px)

DESCRIPTION

Steve Newcomb's deck from the tech talk he gave on the second day of HTML5DevConf in San Francisco. Sign up for the famo.us beta at http://famo.us/

Citation preview

Page 1: HTML5 DevConf Oct 2012 Tech Talk

page 1famous.

@stevenewcomb

Web App Performancethe story of becoming famo.us

beta signupwww.famo.us

Page 2: HTML5 DevConf Oct 2012 Tech Talk

page 2famous.

the story of becoming famo.us

a lot of things didn’t make sense

Page 3: HTML5 DevConf Oct 2012 Tech Talk

page 3famous.

the story of becoming famo.us

about 2 years ago, we got funded to build consumer identity app

Page 4: HTML5 DevConf Oct 2012 Tech Talk

page 4famous.

the story of becoming famo.us

it had a very ambitious user interface

Page 5: HTML5 DevConf Oct 2012 Tech Talk

page 5famous.

the story of becoming famo.us

we decided to build it in HTML5

Page 6: HTML5 DevConf Oct 2012 Tech Talk

page 6famous.

the story of becoming famo.us

it needed to work on lots of devices including

iPad1 + iPad2 + iPad3

phones, tablets, pcs and game consoles

Page 7: HTML5 DevConf Oct 2012 Tech Talk

page 7famous.

the story of becoming famo.us

it needed to work on iOS and Android as a web app and inside a native wrapper

Page 8: HTML5 DevConf Oct 2012 Tech Talk

page 8famous.

the story of becoming famo.us

it needed to handle many inputs including touch, keyboard, mouse and gesturing systems

Page 9: HTML5 DevConf Oct 2012 Tech Talk

page 9famous.

the story of becoming famo.us

we started knowing nothing

Page 10: HTML5 DevConf Oct 2012 Tech Talk

page 10famous.

the story of becoming famo.us

we hit every performance issue you can imagine

Page 11: HTML5 DevConf Oct 2012 Tech Talk

page 11famous.

the story of becoming famo.us

we battled through many false promisses

Page 12: HTML5 DevConf Oct 2012 Tech Talk

page 12famous.

the story of becoming famo.us

we went through many frustrating experiences

Page 13: HTML5 DevConf Oct 2012 Tech Talk

page 13famous.

we learned a lot of things

the story of becoming famo.us

Page 14: HTML5 DevConf Oct 2012 Tech Talk

page 14famous.

we’d like to share our journey with you

the story of becoming famo.us

Page 15: HTML5 DevConf Oct 2012 Tech Talk

page 15famous.

our first big realization

CSS3 can completely ruin your performance

Page 16: HTML5 DevConf Oct 2012 Tech Talk

page 16famous.

examples

• -webkit-box-shadow: 60px black;

• -webkit-transform-style: preserve-3D;

• -webkit-text-stroke: 1px transparent;

• -webkit-transform: translateZ(0);

• -webkit-transition: all 1s ease-in-out;

• @keyframes mymove

and 50 more things...

Page 17: HTML5 DevConf Oct 2012 Tech Talk

page 17famous.

our first big realization

there are basically no debug tools to find these things

Page 18: HTML5 DevConf Oct 2012 Tech Talk

page 18famous.

our first big realization

this causes discomfort between designers and engineers

Page 19: HTML5 DevConf Oct 2012 Tech Talk

page 19famous.

the impact

• we catalogued all of these quirks

• we refactored all of our CSS

• one designer was killed, one maimed

• we had to audit any 3rd party library that touched CSS

sucked

sucked

confusing

unfortunate

The realization had a dramatic impacts

Page 20: HTML5 DevConf Oct 2012 Tech Talk

page 20famous.

reading material

Y U NO LINKS

Page 21: HTML5 DevConf Oct 2012 Tech Talk

page 21famous.

our second big realization

Learning to code for computers first has masked bad coding habits

Page 22: HTML5 DevConf Oct 2012 Tech Talk

page 22famous.

We had to relearn many things to optimize our code for mobile

DOM Manipulation

Event Handling

Data Handling

Image Handling

our second big realization

Page 23: HTML5 DevConf Oct 2012 Tech Talk

page 23famous.

• we learned the performance optimized methods

• we refactored all of our app specific javascript libraries

• we had to audit any 3rd party library that touched DOM, events, data or images

meh

interesting

The realization had a dramatic impacts

our second big realization

sucked

Page 24: HTML5 DevConf Oct 2012 Tech Talk

page 24famous.

reading material

Y U NO LINKS

Page 25: HTML5 DevConf Oct 2012 Tech Talk

page 25famous.

our fourth big realization

Safari and Chrome are not created equally

Page 26: HTML5 DevConf Oct 2012 Tech Talk

page 26famous.

• webkit implementation• bezier curves and preserve-3D

• version differences

• uncanny valleys

• JS engines

• device differences

• retarded things we are still too angry to talk about

some examples

Page 27: HTML5 DevConf Oct 2012 Tech Talk

page 27famous.

• we had to catalogue the differences

• we refactored all code to take these differences into account

• two devices were destroyed (Android)

• we had to audit any 3rd party library to see how they handled the differences

The realization had a dramatic impacts

sucked

sucked

sucked

unfortunate

the real work began

Page 28: HTML5 DevConf Oct 2012 Tech Talk

page 28famous.

reading material

Y U NO LINKS

Page 29: HTML5 DevConf Oct 2012 Tech Talk

page 29famous.

our fifth big realization

a lot of HTML5 components don’t work or don’t work like you’d expect

Y U NO WORK

Page 30: HTML5 DevConf Oct 2012 Tech Talk

page 30famous.

some examples

Y U NO WORK

• cache manifest

• android touch events

• HTML5 video

Page 31: HTML5 DevConf Oct 2012 Tech Talk

page 31famous.

the real work work began

• we catalogued the which ones didn’t work

• we removed all usage of these things

• we had to audit any 3rd party library to see how they handled the differences

The realization had a dramatic impacts

easy

sucked

frustrating

Page 32: HTML5 DevConf Oct 2012 Tech Talk

page 32famous.

our sixth big realization

a lot of our favorite libraries were useless

Page 33: HTML5 DevConf Oct 2012 Tech Talk

page 33famous.

some examples

• jQuery Animations

• jQuery Plugins

• jQuery

• Isotope

• Any thing that was built originally for computers and touched the DOM or Events

Page 34: HTML5 DevConf Oct 2012 Tech Talk

page 34famous.

the impact

• we catalogued the which ones didn’t work

• we removed all usage of these things

• we re-wrote all the things we had to remove

The realization had a dramatic impacts

sucked

frustrating

sucked

Page 35: HTML5 DevConf Oct 2012 Tech Talk

page 35famous.

DOM Manipulation Tricks

let’s try some exotic DOM manipulation techniques

Page 36: HTML5 DevConf Oct 2012 Tech Talk

page 36famous.

some examples

advanced DOM manipulation techniques

• DOM object re-use• 3 panels method• the event horizon method

Page 37: HTML5 DevConf Oct 2012 Tech Talk

page 37famous.

let’s try some exotic frame rate techniques

GPU Tricks

Page 38: HTML5 DevConf Oct 2012 Tech Talk

page 38famous.

some examples

Example of advanced DOM manipulation techniques

• Request animation frame

• Frame Rate throttling

• Fake multi-thread javascript

Page 39: HTML5 DevConf Oct 2012 Tech Talk

page 39famous.

impacts on effort

In many ways dealing with the GPU is like working with a magical black box that you have little to no visibility into

• buffer size• resource limits• object count

Good luck figure out when your app is about to blow the GPU up

Page 40: HTML5 DevConf Oct 2012 Tech Talk

page 40famous.

reading material

Y U NO LINKS

Page 41: HTML5 DevConf Oct 2012 Tech Talk

page 41famous.

success (kind of)

1 year later (March 2011)

Page 42: HTML5 DevConf Oct 2012 Tech Talk

page 42famous.

the story of becoming famo.us

a lot of things didn’t make sense

JANK

Page 43: HTML5 DevConf Oct 2012 Tech Talk

page 43famous.

a fundamental question

we were able to make it performant, but at what price?

Page 44: HTML5 DevConf Oct 2012 Tech Talk

page 44famous.

Coding for mobile apps is much less forgiving that coding for websites

• performance problems are often a factor of many things interacting with each other

• as your codebase grows, the number of either library specific or app specific interactions that affect performance constantly grows

• every time a new performance problem arises, the complexity of solving it grows

the reality check

Page 45: HTML5 DevConf Oct 2012 Tech Talk

page 45famous.

what was the real solution?

why not just build everything in webGL or Canvas?

Page 46: HTML5 DevConf Oct 2012 Tech Talk

page 46famous.

what do you lose with WebGL or Canvas?

Event handling at the object level

Portability of exisiting DOM, includingText layout in 2DMost CSS effectsButtons and form elementsText selection / highlighting

Contextual information of objects within

WebGL is like a hologram while HTML + CSS transforms is the real thing

Page 47: HTML5 DevConf Oct 2012 Tech Talk

page 47famous.

what was the real solution?

documents apps 2D rendered 3D rendered

HTML ? canvas WebGL

there wasn’t anything specifically designed for apps

Page 48: HTML5 DevConf Oct 2012 Tech Talk

page 48famous.

what was the real problem?

browsers were built to render documents and not apps

Page 49: HTML5 DevConf Oct 2012 Tech Talk

page 49famous.

understanding WebKit

parsingDOM tree

constructionRender treeconstruction

Layout of Render Tree

Render Tree Painting

WebCore

Simplified Render

Page 50: HTML5 DevConf Oct 2012 Tech Talk

page 50famous.

understanding WebKit

parsingDOM tree

constructionRender treeconstruction

Layout of Render Tree

Render Tree Painting

WebCore

designed to render documents

Page 51: HTML5 DevConf Oct 2012 Tech Talk

page 51famous.

understanding WebKit

Render Engine

Physics Engine

famo.us

Rules Framework

Page 52: HTML5 DevConf Oct 2012 Tech Talk

page 52famous.

understanding WebKit

parsingDOM tree

constructionRender treeconstruction

Layout of Render Tree

Render Tree Painting

WebCore

modify the inefficient parts

Render Engine

Physics Engine

famo.us

Rules Framework

Page 53: HTML5 DevConf Oct 2012 Tech Talk

page 53famous.

building the render engine

• Energy Module (defines and instantiates energy agents)

• Camera Kinematics Module (controls camera movement behavior & events)

• Camera Module (positions camera and adjusts perspective)

• TransitionHelper Module (handles animation of multiple surfaces)

• Surface Kinematics Module (positions surfaces and applies kinematics)

• Matrix Module (performs efficient matrix math)

Page 54: HTML5 DevConf Oct 2012 Tech Talk

page 54famous.

how does it work?

ignore the CSS3 transition primitives

compute the transforms in our render engine

inject our computed transforms into -webkit-transform: matrix3D

effectively skipping the browsers inefficient rendering process meant for documents

Page 55: HTML5 DevConf Oct 2012 Tech Talk

page 55famous.

DEMO PLEASE

Y U NO SHOW ME

Page 56: HTML5 DevConf Oct 2012 Tech Talk

page 56famous.

Physics Engine

use kinematic actors to effect motion and user interaction in the system

enable designers to tune without touching CSS

enable engineers to build custom components

enable enginers to build new kenematic actors or change the engine itself

yu kant b srs

Page 57: HTML5 DevConf Oct 2012 Tech Talk

page 57famous.

DEMO PLEASE

Y U NO SHOW ME

Page 58: HTML5 DevConf Oct 2012 Tech Talk

page 58famous.

step 3

let’s build our own framework

Page 59: HTML5 DevConf Oct 2012 Tech Talk

page 59famous.

specifically

manage all of the input mechanisms like touch, mouse, keyboard and gestures

manage the differences amongst browsers, versions and devices

Page 60: HTML5 DevConf Oct 2012 Tech Talk

page 60famous.

DEMO PLEASE

Y U NO SHOW ME

Page 61: HTML5 DevConf Oct 2012 Tech Talk

page 61famous.

the realization

the engine and the framework were more important to us than the product

Page 62: HTML5 DevConf Oct 2012 Tech Talk

page 62famous.

the framework

scaffolds, ui and ux components and all the things you need to build apps

let developers build and share their own app templates, scaffolds and components too

enable developers to get down to the source code if they need to

Page 63: HTML5 DevConf Oct 2012 Tech Talk

page 63famous.

the FAQs

Are you planning on being full stack or doing just one thing well and integrating with other MVCs?designed to be just the view layer in an MVC

Do you plan on working with Backbone.js?YES

Will there be a public GitHub repo with an open source license?YES

Will there be a commercial license?YES

Page 64: HTML5 DevConf Oct 2012 Tech Talk

page 64famous.

how to get involved

beta [email protected]@befamous

Page 65: HTML5 DevConf Oct 2012 Tech Talk

page 65famous.

links

CSS 3D Transformshttps://www.webkit.org/blog/386/3d-transforms/http://www.webkit.org/blog-files/3d-transforms/poster-circle.htmlhttp://desandro.github.com/3dtransforms/http://html5rubik.com/tutorial/http://html5rubik.com/tutorial/step3/index.htmlhttp://www.paulrhayes.com/experiments/sphere/http://css3.bradshawenterprises.comhttp://9elements.com/html5demos/matrix3d/http://www.the-art-of-web.com/css/3d-transforms/http://dev.opera.com/articles/view/understanding-the-css-transforms-matrix/http://24ways.org/2010/intro-to-css-3d-transformshttp://www.webkit.org/blog-files/3d-transforms/transform-style.htmlhttp://www.edankwan.com/lab/css3dEarthhttp://www.netmagazine.com/features/20-stunning-examples-css-3d-transformshttp://cbateman.com/blog/head-coupled-3d-transforms/http://coding.smashingmagazine.com/2012/04/17/beercamp-an-experiment-with-css-3d/http://acko.net/blog/making-love-to-webkit/https://news.ycombinator.com/item?id=3470736http://www.satine.org/archives/2009/07/11/snow-stack-is-here/http://coding.smashingmagazine.com/2012/01/06/adventures-in-the-third-dimension-css-3-d-transforms/

3D Linear Algebra - Advancedhttp://www.robertblum.com/articles/2005/02/14/decomposing-matriceshttp://en.wikipedia.org/wiki/Householder_transformationhttp://en.wikipedia.org/wiki/QR_decompositionhttp://en.wikipedia.org/wiki/Transformation_matrix

Page 66: HTML5 DevConf Oct 2012 Tech Talk

page 66famous.

links

Documentationhttps://developer.mozilla.org/en-US/docs/CSS/transform?redirectlocale=en-US&redirectslug=CSS%2F-moz-transformhttps://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariCSSRef/Articles/Functions.htmlhttp://www.w3.org/TR/css3-2d-transforms/http://www.w3.org/TR/css3-3d-transforms/https://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/WebKitCSSMatrixClassReference/WebKitCSSMatrix/WebKitCSSMatrix.html

Troubleshootinghttp://stackoverflow.com/questions/6843367/css3-transforms-cause-screen-flickering-or-aliased-font

Animation, requestAnimationFrame and performancehttp://paulirish.com/2011/requestanimationframe-for-smart-animating/https://developer.mozilla.org/en-US/docs/CSS/@keyframeshttp://www.w3.org/TR/css3-animations/http://creativejs.com/resources/requestanimationframe/https://developer.mozilla.org/en-US/docs/DOM/window.requestAnimationFrame?redirectlocale=en-US&redirectslug=DOM%2Fwindow.mozRequestAnimationFramehttp://www.html5rocks.com/en/tutorials/speed/animations/http://www.html5rocks.com/en/tutorials/doodles/lem/http://www.planetb.ca/2012/03/html5-game-programming-gems-requestanimationframe/TranslateZ(0), preserve-3D and performancehttp://stackoverflow.com/questions/10814178/css-performance-relative-to-translatez0http://creativejs.com/2011/12/day-2-gpu-accelerate-your-dom-elements/http://stickmanventures.com/labs/demo/spinning-gears-Chrome-preserve-3d/http://stackoverflow.com/questions/7908493/considerations-for-css3-transition-performancehttp://albertogasparin.it/articles/2011/06/ios-css-animations-performances/http://jsperf.com/translate3d-vs-xy/29

Page 67: HTML5 DevConf Oct 2012 Tech Talk

page 67famous.

links

Other CSS Issueshttp://nerds.airbnb.com/box-shadows-are-expensive-to-paint

Interesting Discussions on HTML5 performance and feature supporthttp://lists.w3.org/Archives/Public/public-coremob/2012Sep/0021.htmlhttp://news.ycombinator.com/item?id=4526593https://plus.google.com/106300407679257154689/posts/PBxtaphMDGJhttps://plus.google.com/106300407679257154689/posts/NEAuwZ7v27Bhttp://updates.html5rocks.com/2012/07/How-to-measure-browser-graphics-performance

Information and videos on how browsers workhttp://www.html5rocks.com/en/tutorials/internals/howbrowserswork/http://vimeo.com/44182484http://www.youtube.com/watch?v=xuMWhto62Eo

Touch Issues, Discussions and Solutionshttp://www.html5rocks.com/en/mobile/touch/http://smus.com/mouse-touch-pointer/https://github.com/borismus/pointer.jshttps://dl.dropbox.com/u/7479257/pointevents_strawman.txthttp://www.lukew.com/ff/entry.asp?1533

Information on browser support:https://developers.facebook.com/html5/blog/post/2012/04/03/ringmark-is-now-open-source/

Information on CSS3 Transitions (nota bene: they aren't performant enough so we built our own animation curves for transitions in famo.us)http://dev.w3.org/csswg/css3-transitions/

Page 68: HTML5 DevConf Oct 2012 Tech Talk

page 68famous.

links

Appcache and storagehttp://www.alistapart.com/articles/application-cache-is-a-douchebag/https://speakerdeck.com/u/jaffathecake/p/application-cache-douchebag

General Javascript Performance Advicehttp://blog.tojicode.com/2012/04/if-i-built-physics-engine.htmlhttp://blog.tojicode.com/2012/03/javascript-memory-optimization-and.htmlhttps://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascripthttp://net.tutsplus.com/tutorials/javascript-ajax/stop-nesting-functions-but-not-all-of-them/http://www.html5rocks.com/en/tutorials/speed/v8/http://news.ycombinator.com/item?id=4643611

Three panel method approach to Infinite scrollhttp://cubiq.org/swipeview

Code review of Quake3 and Doom3, which offer lots of good insight into producing a performance 3D app that works over a network where latency is a problemhttp://fabiensanglard.net/quake3/index.phphttp://fabiensanglard.net/doom3/index.php