AKI SAARINEN, REAKTOR...

50
FAST and EFFICIENT Tizen HTML5 mobile applications AKI SAARINEN, REAKTOR JAPAN @akisaarinen http://reaktor.co.jp/en/

Transcript of AKI SAARINEN, REAKTOR...

Page 1: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

FAST and EFFICIENT Tizen HTML5 mobile applications

AKI SAARINEN, REAKTOR JAPAN @akisaarinen

http://reaktor.co.jp/en/

Page 2: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

FAST &

EFFICIENT

Page 3: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Page 4: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

1 Measure! 2 Start-up time 3 Run-time performance

Page 5: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

1 MEASURE!

Page 6: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Measure before optimizing

“— a wise man

Page 7: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• WebKit Web Inspector • Tizendev: start-up • Tizendev: framerate

Available tools

Page 8: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

WebKit Web Inspector

Page 9: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

TizenDev

• Automated deploying of app • Automated start-up timing • Automated FPS measurements • http://github.com/reaktor/tizendev

Page 10: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

TizenDev: start-up time

runs:          30  mean:  1708ms  std:        63ms

Page 11: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

TizenDev: framerate

samples:        100  mean:        58  FPS  std:            4  FPS

Page 12: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• WebKit Web Inspector • Tizendev: start-up • Tizendev: framerate

Available tools

Page 13: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

2 START-UP

Page 14: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

LESS IS MORE

Page 15: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• Lazy-loading • Minification • Reflow • Native API calls • Parallelization

Page 16: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Large codebase, all loaded and parsed at start-up time

Page 17: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Large codebase, all loaded and parsed at start-up time

Page 18: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Code to show first screen

Modularized pieces to show other views on-demand

Page 19: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

UglifyJS1 kilobyte ~= 1 ms

Page 20: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Avoid reflow

Page 21: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Avoid reflow REALLY!

Page 22: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Example: Calling width() of an element

Page 23: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

!container.find("li").each(function()  {      var  listItem  =  $(this);      listItem.text(item.width());  });  !

forces reflow

Page 24: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

container.appendTo($("body"));  

!container.find("li").each(function()  {      var  listItem  =  $(this);      listItem.text(item.width());  });  !

container.detach();  

Page 25: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

container.appendTo($("body"));  

!container.find("li").each(function()  {      var  listItem  =  $(this);      listItem.text(item.width());  });  !

container.detach();  

Page 26: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

1000 elements (MacBook Pro)

!

2000 ms 60 ms

Page 27: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• Defer execution • Use localstorage • Only fetch needed data

Native APIs

Page 28: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Parallelize

• Resources • Service calls

Page 29: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Page 30: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Page 31: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• Do lazy-loading • Use minification • Avoid reflow • Careful with native APIs • Parallelize

Page 32: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

3 RUN-TIME

Page 33: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

60 FPS

Page 34: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• DOM modifications • Pre-loading • CSS3 transitions • Scrolling

Page 35: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

DOM =

SLOW

Page 36: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

display: none; !

+ 5-10 FPS

Page 37: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

21 3(pre-load) (pre-load)visible

Page 38: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Accelerated CSS3 transitions

Page 39: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

jQuery.animate() CSS3

NO: YES:

Page 40: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

left: 0px -> 100px translate3d()

NO: YES:

Page 41: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

background-color: ...; opacity: 0.2;

NO: YES:

Page 42: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

-webkit-transform: translate3d(0,0,0);

http://stackoverflow.com/questions/3461441/prevent-flicker-on-webkit-transition-of-webkit-transform

Enable 3D acceleration

Page 43: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Trigger animation in next render cycle

Page 44: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

setTimeout(function()  {      element.css(          “-­‐webkit-­‐transform”,          “translate3d(100,0,0)”      );  },  0);

Page 45: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

iScroll or other JavaScript library overflow: scroll; -webkit-overflow-scroll: touch;

Momentum scrollingNO: NO: YES:

Page 46: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• DOM is slow • Do pre-loading • Use CSS3 transitions • Use overflow scrolling

Page 47: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

1 Measure! 2 Start-up time 3 Run-time performance

Re-cap!

Page 48: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

• Performance is important • Measure before optimizing • Minimize actions at start-up • Pay attention to FPS

Page 49: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›

‹#›

Thank you!@akisaarinen

Page 50: AKI SAARINEN, REAKTOR JAPANdownload.tizen.org/misc/media/conference2014/slides/tdc...-webkit-transform: translate3d(0,0,0);  Enable 3D acceleration ‹#›