FAST and EFFICIENT Tizen HTML5 mobile applications AKI SAARINEN, - - PowerPoint PPT Presentation

fast and efficient
SMART_READER_LITE
LIVE PREVIEW

FAST and EFFICIENT Tizen HTML5 mobile applications AKI SAARINEN, - - PowerPoint PPT Presentation

FAST and EFFICIENT Tizen HTML5 mobile applications AKI SAARINEN, REAKTOR JAPAN @akisaarinen http://reaktor.co.jp/en/ FAST & EFFICIENT # # 1 Measure! 2 Start-up time 3 Run-time performance # 1 MEASURE! #


slide-1
SLIDE 1

FAST and EFFICIENT

Tizen HTML5 mobile applications

AKI SAARINEN, REAKTOR JAPAN

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

slide-2
SLIDE 2 ‹#›

FAST & EFFICIENT

slide-3
SLIDE 3 ‹#›
slide-4
SLIDE 4 ‹#›

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

slide-5
SLIDE 5 ‹#›

1 MEASURE!

slide-6
SLIDE 6 ‹#›

Measure before

  • ptimizing

— a wise man

slide-7
SLIDE 7 ‹#›
  • WebKit Web Inspector
  • Tizendev: start-up
  • Tizendev: framerate

Available tools

slide-8
SLIDE 8 ‹#›

WebKit Web Inspector

slide-9
SLIDE 9 ‹#›

TizenDev

  • Automated deploying of app
  • Automated start-up timing
  • Automated FPS measurements
  • http://github.com/reaktor/tizendev
slide-10
SLIDE 10 ‹#›

TizenDev: start-up time

runs: ¡ ¡ ¡ ¡ ¡30 ¡ mean: ¡1708ms ¡ std: ¡ ¡ ¡ ¡63ms

slide-11
SLIDE 11 ‹#›

TizenDev: framerate

samples: ¡ ¡ ¡ ¡100 ¡ mean: ¡ ¡ ¡ ¡58 ¡FPS ¡ std: ¡ ¡ ¡ ¡ ¡ ¡4 ¡FPS

slide-12
SLIDE 12 ‹#›
  • WebKit Web Inspector
  • Tizendev: start-up
  • Tizendev: framerate

Available tools

slide-13
SLIDE 13 ‹#›

2 START-UP

slide-14
SLIDE 14 ‹#›

LESS

IS MORE

slide-15
SLIDE 15 ‹#›
  • Lazy-loading
  • Minification
  • Reflow
  • Native API calls
  • Parallelization
slide-16
SLIDE 16 ‹#›

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

slide-17
SLIDE 17 ‹#›

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

slide-18
SLIDE 18 ‹#›

Code to show first screen Modularized pieces to show other views

  • n-demand
slide-19
SLIDE 19 ‹#›

UglifyJS 1 kilobyte ~= 1 ms

slide-20
SLIDE 20 ‹#›

Avoid reflow

slide-21
SLIDE 21 ‹#›

Avoid reflow

REALLY!

slide-22
SLIDE 22 ‹#›

Example: Calling width() of an element

slide-23
SLIDE 23 ‹#›
  • container.find("li").each(function() ¡{ ¡

¡ ¡var ¡listItem ¡= ¡$(this); ¡ ¡ ¡listItem.text(item.width()); ¡ }); ¡

  • forces reflow
slide-24
SLIDE 24 ‹#›

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

  • container.find("li").each(function() ¡{ ¡

¡ ¡var ¡listItem ¡= ¡$(this); ¡ ¡ ¡listItem.text(item.width()); ¡ }); ¡

  • container.detach(); ¡
slide-25
SLIDE 25 ‹#›

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

  • container.find("li").each(function() ¡{ ¡

¡ ¡var ¡listItem ¡= ¡$(this); ¡ ¡ ¡listItem.text(item.width()); ¡ }); ¡

  • container.detach(); ¡
slide-26
SLIDE 26 ‹#›

1000 elements (MacBook Pro)

  • 2000 ms 60 ms
slide-27
SLIDE 27 ‹#›
  • Defer execution
  • Use localstorage
  • Only fetch needed data

Native APIs

slide-28
SLIDE 28 ‹#›

Parallelize

  • Resources
  • Service calls
slide-29
SLIDE 29 ‹#›
slide-30
SLIDE 30 ‹#›
slide-31
SLIDE 31 ‹#›
  • Do lazy-loading
  • Use minification
  • Avoid reflow
  • Careful with native APIs
  • Parallelize
slide-32
SLIDE 32 ‹#›

3 RUN-TIME

slide-33
SLIDE 33 ‹#›

60 FPS

slide-34
SLIDE 34 ‹#›
  • DOM modifications
  • Pre-loading
  • CSS3 transitions
  • Scrolling
slide-35
SLIDE 35 ‹#›

DOM = SLOW

slide-36
SLIDE 36 ‹#›

display: none;

  • + 5-10 FPS
slide-37
SLIDE 37 ‹#›

2 1 3

(pre-load) (pre-load) visible

slide-38
SLIDE 38 ‹#›

Accelerated

CSS3 transitions

slide-39
SLIDE 39 ‹#›

jQuery.animate() CSS3 NO: YES:

slide-40
SLIDE 40 ‹#›

left: 0px -> 100px translate3d() NO: YES:

slide-41
SLIDE 41 ‹#›

background-color: ...;

  • pacity: 0.2;

NO: YES:

slide-42
SLIDE 42 ‹#›
  • webkit-transform: translate3d(0,0,0);

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

Enable 3D acceleration

slide-43
SLIDE 43 ‹#›

Trigger animation in next render cycle

slide-44
SLIDE 44 ‹#›

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

slide-45
SLIDE 45 ‹#›

iScroll or other JavaScript library

  • verflow: scroll;
  • webkit-overflow-scroll: touch;

Momentum scrolling

NO: NO: YES:

slide-46
SLIDE 46 ‹#›
  • DOM is slow
  • Do pre-loading
  • Use CSS3 transitions
  • Use overflow scrolling
slide-47
SLIDE 47 ‹#›

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

Re-cap!

slide-48
SLIDE 48 ‹#›
  • Performance is important
  • Measure before optimizing
  • Minimize actions at start-up
  • Pay attention to FPS
slide-49
SLIDE 49 ‹#›

Thank you!

@akisaarinen

slide-50
SLIDE 50