SlideShare a Scribd company logo
Web Engine-Aware 
Performace Optimization of 
HTML5 Games for Mobile Devices 
Sang Seok Lim (sangseok.lim@sk.com), 
Director, SK planet
Agenda 
● Web Engine Internal 
● Web Engine Performance Analysis 
● HTML5 Game Basics 
● Performace Optimization Techniques 
● Case study
Commercial Use Cases of HTML5 Games 
● In-app HTML5 games 
○ OK Cashbag Arcade (June, 2014) 
○ Syrup Plant Pop (October, 2014) 
● In-app means a hybrid app 
○ embedded through WebView 
○ not for a browser which is incapable of enabling BM 
● Goal from the business viewpoint 
○ user rentention for keeping/increasing UV of native 
apps
HTML5 Game Architecture Overview 
● from the viewpoint of performance, 
DOM/JavaScript APIs of HTML5 are tightly 
coupled to underlying SW/HW layers 
Game Logic (HTML/CSS/JavaScript) 
Game Engine (JavaScript, WebWorker) 
DOM/JavaScript API 
Webview Widget 
Webkit/Blink Engine 
Android/iOS 
HW(ARM CPU, OpenGL ES GPU)
Chrome Browser Architecture 
similar to Chrome Webview
HTML5 Game RunTime: WebKit 
● Layout/Rendering 
○ 2D, 3D graphics by GPU, text rendering 
● Sound 
○ <audio>, WebAudio 
● Physics 
○ Javascript engine, JIT, multi-core by WebWorker 
DOM <canvas> Physics Engine 
Parser Layout Rendering 
2D 
graphics 
3D 
graphics 
Text 
Rendering 
JavaScript Engine 
(JIT) 
multimedia 
(sound) 
Game 
Web 
engine 
Platform
Parsing before Rendering
WebKit Internal: Layout 
● Calculate left top, 
width, height of all 
DOM nodes 
contained in a 
HTML document 
● Group a set of 
DOM nodes then, 
stack the resultant 
groups accordingly 
left, top, width, height 
ordering layers 
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
Internal Data Structure for Rendering
WebKit Internal: Rendering 
● DOM Rendering 
○ Image + text 
○ CSS 2D/3D rendering 
■ GPU Acceleration 
● 2D graphics 
○ canvas/SW 
○ canvas/OpenGL ES 
● 3D graphics 
○ WebGL/OpenGL ES
DOM Rendering: Image + Text 
● It’s all about handling a image 
○ <img> tag represent a image 
○ text is broken into a serises of images 
Penguin 
P e 
n 
g 
u 
i 
n
DOM Rendering: CSS2D/3D 
● 2D/3D transform matrix 
rotate 
scale translate 
skew
DOM Rendering: CSS2D/3D 
● RenerLayers are selectively mapped into 
GPU textures for being rendered by GPU
DOM Rendering: CSS2D/3D by HW acceleration 
● 2D/3D transform of DOM nodes by GPU 
Penguin 
Penguin 
Penguin 
Texture generation by CPU Texture based animation by GPU
Texture Visualization by Inspector
<canvas> Rendering 
● 2D primitive 
○ path, curve, polygon 
○ fill, stroke 
○ image manipulation 
○ pixel manipulation 
● <canvas> primitive HW acceleraton 
○ image manipulation 
● <canvas> buffer itself is a GPU texture
WebGL Rendering 
● JavaScript wrapper of OpenGL
Compatibility across Mobile Devices 
● Not all of the rendering models can be used 
for mobile devices right now 
● Compatibility summary 
○ CSS 2D/3D (HW) 
■ ICS 4.0 >, iOS 4.0 > 
○ canvas (SW) 
○ Android 2.3 <= 
● canvas (HW) 
○ Android 4.0 >, iOS 5.0 > 
● WebGL 
○ iOS 8.0 > 
○ Android L >
OS Distribution of Customers 
OK Cashbag App (June, 2014) 
the critical 
defect by 
Google
General Rendering Back-end 
for Mobile Devices 
● <canvas> 2D for Game object rendering 
○ HW acceleration 
● DOM for Game UI 
○ 2D/3D by GPU
App-embedded Branded Casual Game 
● In-app play for user retention 
● No app update via app store
<canvas> based Game Development 
Browser limitations 
● Browser engine as a game platform 
○ rendering 
■ <canvas>, WebGL, DOM 
○ sound 
■ <audio> 
■ WebAudio 
○ resource loading 
■ XHR/<img> 
○ input 
■ touchstart, touchmove, touchend 
○ DPI management 
■ image resource scale up/down
<canvas> based Game Development 
Into Reality 
● The limitations of open source game engine 
○ only for PC chrome/Firefox 
○ does not meet the hard requirements for mobile OS 
● In-house game engine development 
○ to achieve stable 20 fps on our customer’s device 
■ higher is better even on android 2.3 and iOS 5.0 
○ reasonable touch response delay 
○ no garbage collection whiling playing 
● Further information 
○ http://www.slideshare.net/senxation/html5-ok-33344593
<canvas> Game Main Loop 
● As easy as animation by flipping pages
Representaion of Game Objects 
● Two approaches 
○ static image generation: offline image based 
○ dynamic image generation: drawing primitive 
combination based 
● Each approach has its own pros and cons 
○ performance 
○ design-constraint
Image based Object Representation 
● A series of sprite image cropping/scaling 
○ ctx.drawImage(src, dest) 
○ the performance of game is decided by drawImage() 
● Static image generation (offline) 
○ one for each low, mid, high resolution devices
Drawing Primitive Combination 
● Dynamic image generation 
○ draw an object onto a buffer with the prior 
knowledge of device DPI, target pixel dimension 
○ minimize image scaling during rendering 
http://simeonvisser.hubpages.com/hub/HTML5-Tutorial-Drawing-Circles-and-Arcs
Summary of Pros and Cons 
● Image based (offline) 
○ overall performance limited by image scaling 
primitive 
○ designer-friendly 
● Drawing primitive based (online) 
○ higher performance 
○ be an enemy to a developer with lower IQ 
○ be an enemy to a designer
Performance of <canvas> in Detail 
in WebView for Hybrid App 
● The killing bottleneck is “PAINTING” 
● Performance challenges 
○ no <canvas> HW acceleration: android 2.3, iOS 4.0 
○ Kitkat Chrome Webview’s critical error by Google 
■ no HW acceleration on 4.4, 4.4.2 Chrome 
Webview 
■ fixed at 4.4.3 
■ but market share of 4.4.2 in Korea → 65%
The Problem Definition 
when it comes to developing <canvas> game for mobile devices 
● Android 2.3 without canvas HW acceleration 
○ together with canvas acceleration 
● Android /4.4[0-2]/ without canvas HW 
acceleration
Performance Analysis of Kitkat Webview 
● To find the performance limiting factors 
○ painting size 
○ the number of drawing primitive calls 
○ DOM tree complexity 
● System under test 
○ Optimus G Pro (4.4.2) 
○ Nexus 5 (4.4)
Performan Analysis I 
● Partial rendering 
○ reuse the content of a previous frame buffer 
● Full rendering 
○ reset a frame buffer every rendering 
painting area size 
fps 
The Larger, The Slower
Performance Analysis II 
● Increase the number of painting areas 
○ a painting area size is fixed to 25x25 
fps 
the number of painting area
Performance Analysis III 
● Impact analysis with respect to DOM complexity
Performance Analysis V 
● Impact analysis with respect to DOM complexity 
● Severe fps fluctuation
Summary of Performance Analysis 
● In proportion to the size of painting area, 
painting performance (fps) is decreased 
● The more complex DOM tree containing 
<cavas> is, the more severely fps fluctuates
Performance Improvement 
● 5 practical techniques 
○ DOM/<canvas> hybrid rendering for game objects 
○ Static object pool for keeping garbage collector 
asleep 
○ Smart repaint by tracing invaldated areas 
○ Image resource offline manipulation 
○ Minimize a DOM tree complexity 
● not all of them are applicable at the same 
time 
○ depending on game scenario, game performance 
requirement, smart repaint/hybrid rendering can be 
selectively applicable
DOM/<canvas> Hybrid Rendering 
painting size minimization 
● Selectively separate game objects contained in 
<canvas>, and then paint them through DOM 
canvas only canvas/DOM Hybrid
DOM/<canvas> Hybrid Rendering 
implementation detail: DOM node pool 
● Manage/reuse a set of DOM nodes with a 
background image of a game object
Smart Repaint 
Repaint Region Trace 
● Reuse the content of the frame buffer of n-1 
frame for rendering n frame 
● Trace the invalidated area, paint only 
invalidated area
Source Image Size Matters A LOT! 
● A sprite image is generally used to minimize # of 
network req 
● Performance anomaly 
○ the larger the source image is, the slower fps is, even when the 
destination size is fixed 
separate
Garbage Collector Stops The World 
● All objects are allocated from a object pool 
● Implementation of a object pool matters 
○ single Array, double Array, linked list 
○ http://jsperf.com/objectpool-performance-comparison
Static Object Pool Performance Comparision 
● Single array by Array.push/pop is the best 
○ poor performance of Array.spice() 
● Complete suppression of GC is impossible
Dive into Resolution Issue 
● A designer-generated image is scaled 
up/down 4 times at most implicitly 
○ canvas.width, canvas.height 
○ canvas.style.width, canvas.style.height 
○ ctx.drawImage(source, destination) 
○ window.devicePixelRatio 
● Try not to scale canvas.width/height, canvas. 
style.width/height 
○ how to adapt device resolution in performant way 
○ no fitting/add padding is good for performance 
○ sub optimal display for a user
<canvas> Isolation 
● fps swing around 30% up and down, when 
<canvas> is contained within a document 
with complex DOM tree 
● Seprate <canvas> from DOM based game UI 
○ not easy in the real field where designers/publisher 
and developers from different teams are co-working
Case Study: Flappy Ball 
● DOM/<canvas> hybrid 
● Smart repaint, sprite image separation
2048 
● DOM/GPU only 
● Keeping GPU textures as long as possible
Space 2014 
● Radically reuse a previous frame without 
clearance 
○ Android 2.3 
● clearRect/fillRect
Closing Remark 
● For commercialization on mobile devices, 
performance matters a lot 
○ understading Web-engine internals is essential for 
developing commercial level game successfully 
● open sourced 
○ http://skpla.net/bPqc

More Related Content

PPTX
Amp by Google: The Present And Future Of Quick Content Delivery
PDF
[D2 오픈세미나]2.모바일웹디버깅
PPTX
Android chromium web view
PDF
Booting up with polymer
PDF
Android Chromium Rendering Pipeline
PDF
Deview 2013 mobile browser internals and trends_20131022
PDF
Building a Better Web with HTML5 and CSS3
PDF
The WebKit project
Amp by Google: The Present And Future Of Quick Content Delivery
[D2 오픈세미나]2.모바일웹디버깅
Android chromium web view
Booting up with polymer
Android Chromium Rendering Pipeline
Deview 2013 mobile browser internals and trends_20131022
Building a Better Web with HTML5 and CSS3
The WebKit project

What's hot (20)

PDF
Hardware Acceleration in WebKit
PDF
Chromium ui framework(shared)
PDF
Chrome Internals: Paint and Composition
PDF
Web components api + Vuejs
PPTX
Html5 features: location, history and offline apps
PPTX
Building single page applications
PDF
[D2 오픈세미나]2.browser engine 이형욱_20140523
PDF
Building a Next Generation Mobile Browser using Web technologies
PPTX
Eureko frameworks
PDF
Browsers on Android (Webkit,chromium)
PDF
Chrome & Webkit overview
PPTX
Introducing Kendo UI
PDF
Introduction to Browser Internals
PDF
LCU14 208- Chromium-Blink Migration for RDK
PPTX
Single Page WebApp Architecture
PDF
Web Components and PWA
PDF
Sg conference multiplatform_apps_adam_stanley
PPTX
Kendo UI presentation at JsConf.eu
PDF
Sencha touchonbb10 bootcamp
PDF
The Internal Architecture of Chrome Developer Tools
Hardware Acceleration in WebKit
Chromium ui framework(shared)
Chrome Internals: Paint and Composition
Web components api + Vuejs
Html5 features: location, history and offline apps
Building single page applications
[D2 오픈세미나]2.browser engine 이형욱_20140523
Building a Next Generation Mobile Browser using Web technologies
Eureko frameworks
Browsers on Android (Webkit,chromium)
Chrome & Webkit overview
Introducing Kendo UI
Introduction to Browser Internals
LCU14 208- Chromium-Blink Migration for RDK
Single Page WebApp Architecture
Web Components and PWA
Sg conference multiplatform_apps_adam_stanley
Kendo UI presentation at JsConf.eu
Sencha touchonbb10 bootcamp
The Internal Architecture of Chrome Developer Tools
Ad

Viewers also liked (13)

PDF
The comprehensive guide for optimizing the performance of mobile HTML5 Web ap...
PDF
[C1]웹서비스, 빠를수록 좋다
PDF
NAVER의 웹/HTML5환경 대응 현황
PDF
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
PDF
2015 FOSScon NAVER OSS Governance
PDF
2016 네이버sw기술소개
PDF
HTML5 관점에서 본 2014 모바일 웹 앱 개발 동향과 사례 및 발전 방향 전망
PDF
W3C HTML5 Conference 2015 - NAVER 웹 기술 및 환경 전망
PDF
Web app 개발 방법론
PDF
Angularjs, ionic, cordova 기반 syrup store app 개발 사례 공유
PDF
HTML5 관점에서 2015년 웹 앱 개발 동향과 사례 및 2016년 발전 방향 저...
PDF
Web Framework (웹 프레임워크)
PDF
2017 ict 대전망 framework
The comprehensive guide for optimizing the performance of mobile HTML5 Web ap...
[C1]웹서비스, 빠를수록 좋다
NAVER의 웹/HTML5환경 대응 현황
웹 애플리케이션 프레임웍의 과거,현재 그리고 미래 - 봄날은 간다
2015 FOSScon NAVER OSS Governance
2016 네이버sw기술소개
HTML5 관점에서 본 2014 모바일 웹 앱 개발 동향과 사례 및 발전 방향 전망
W3C HTML5 Conference 2015 - NAVER 웹 기술 및 환경 전망
Web app 개발 방법론
Angularjs, ionic, cordova 기반 syrup store app 개발 사례 공유
HTML5 관점에서 2015년 웹 앱 개발 동향과 사례 및 2016년 발전 방향 저...
Web Framework (웹 프레임워크)
2017 ict 대전망 framework
Ad

Similar to Korea linuxforum2014 html5game-sangseoklim (20)

PDF
W3C HTML5 KIG-The complete guide to building html5 games
PPTX
Сергей Батищев: 2D игры на HTML5: мифы и реальность разработки
PPT
BoosterMedia: Overcome the bottleneck of HTML5 mobile game performance
PPT
HTML5 Canvas Performance optimization
PPTX
HTML5 Animation in Mobile Web Games
PDF
Understanding Hardware Acceleration on Mobile Browsers
PDF
Understanding hardware acceleration on mobile browsers presentation
PDF
One codebase, multiple platforms; Using HTML5/js for game dev
PDF
High Performance Mobile Web Game Development in HTML5
PPTX
HTML5 and Other Modern Browser Game Tech
PPTX
A Holistic Approach to HTML5 Game Design & Development
PDF
Understanding Hardware Acceleration on Mobile Browsers
PDF
Analyzing the Performance of Mobile Web
PPTX
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
PDF
HTML5 Games Status and issues
PDF
Unity optimization techniques applied in Catan Universe
PPTX
Html5 (games)
PPTX
Ogdc 2013 cross platform game development with html5
PPTX
OGDC2013_ Cross platform game development with html5_ Mr Hoang Dinh Quang
PDF
mloc.js 2014 - JavaScript and the browser as a platform for game development
W3C HTML5 KIG-The complete guide to building html5 games
Сергей Батищев: 2D игры на HTML5: мифы и реальность разработки
BoosterMedia: Overcome the bottleneck of HTML5 mobile game performance
HTML5 Canvas Performance optimization
HTML5 Animation in Mobile Web Games
Understanding Hardware Acceleration on Mobile Browsers
Understanding hardware acceleration on mobile browsers presentation
One codebase, multiple platforms; Using HTML5/js for game dev
High Performance Mobile Web Game Development in HTML5
HTML5 and Other Modern Browser Game Tech
A Holistic Approach to HTML5 Game Design & Development
Understanding Hardware Acceleration on Mobile Browsers
Analyzing the Performance of Mobile Web
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
HTML5 Games Status and issues
Unity optimization techniques applied in Catan Universe
Html5 (games)
Ogdc 2013 cross platform game development with html5
OGDC2013_ Cross platform game development with html5_ Mr Hoang Dinh Quang
mloc.js 2014 - JavaScript and the browser as a platform for game development

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
additive manufacturing of ss316l using mig welding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Construction Project Organization Group 2.pptx
PPT
Project quality management in manufacturing
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
PPT on Performance Review to get promotions
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Foundation to blockchain - A guide to Blockchain Tech
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CYBER-CRIMES AND SECURITY A guide to understanding
additive manufacturing of ss316l using mig welding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Construction Project Organization Group 2.pptx
Project quality management in manufacturing
Arduino robotics embedded978-1-4302-3184-4.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Operating System & Kernel Study Guide-1 - converted.pdf
Sustainable Sites - Green Building Construction
bas. eng. economics group 4 presentation 1.pptx
PPT on Performance Review to get promotions
Mechanical Engineering MATERIALS Selection
Lecture Notes Electrical Wiring System Components
Foundation to blockchain - A guide to Blockchain Tech

Korea linuxforum2014 html5game-sangseoklim

  • 1. Web Engine-Aware Performace Optimization of HTML5 Games for Mobile Devices Sang Seok Lim (sangseok.lim@sk.com), Director, SK planet
  • 2. Agenda ● Web Engine Internal ● Web Engine Performance Analysis ● HTML5 Game Basics ● Performace Optimization Techniques ● Case study
  • 3. Commercial Use Cases of HTML5 Games ● In-app HTML5 games ○ OK Cashbag Arcade (June, 2014) ○ Syrup Plant Pop (October, 2014) ● In-app means a hybrid app ○ embedded through WebView ○ not for a browser which is incapable of enabling BM ● Goal from the business viewpoint ○ user rentention for keeping/increasing UV of native apps
  • 4. HTML5 Game Architecture Overview ● from the viewpoint of performance, DOM/JavaScript APIs of HTML5 are tightly coupled to underlying SW/HW layers Game Logic (HTML/CSS/JavaScript) Game Engine (JavaScript, WebWorker) DOM/JavaScript API Webview Widget Webkit/Blink Engine Android/iOS HW(ARM CPU, OpenGL ES GPU)
  • 5. Chrome Browser Architecture similar to Chrome Webview
  • 6. HTML5 Game RunTime: WebKit ● Layout/Rendering ○ 2D, 3D graphics by GPU, text rendering ● Sound ○ <audio>, WebAudio ● Physics ○ Javascript engine, JIT, multi-core by WebWorker DOM <canvas> Physics Engine Parser Layout Rendering 2D graphics 3D graphics Text Rendering JavaScript Engine (JIT) multimedia (sound) Game Web engine Platform
  • 8. WebKit Internal: Layout ● Calculate left top, width, height of all DOM nodes contained in a HTML document ● Group a set of DOM nodes then, stack the resultant groups accordingly left, top, width, height ordering layers https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
  • 9. Internal Data Structure for Rendering
  • 10. WebKit Internal: Rendering ● DOM Rendering ○ Image + text ○ CSS 2D/3D rendering ■ GPU Acceleration ● 2D graphics ○ canvas/SW ○ canvas/OpenGL ES ● 3D graphics ○ WebGL/OpenGL ES
  • 11. DOM Rendering: Image + Text ● It’s all about handling a image ○ <img> tag represent a image ○ text is broken into a serises of images Penguin P e n g u i n
  • 12. DOM Rendering: CSS2D/3D ● 2D/3D transform matrix rotate scale translate skew
  • 13. DOM Rendering: CSS2D/3D ● RenerLayers are selectively mapped into GPU textures for being rendered by GPU
  • 14. DOM Rendering: CSS2D/3D by HW acceleration ● 2D/3D transform of DOM nodes by GPU Penguin Penguin Penguin Texture generation by CPU Texture based animation by GPU
  • 16. <canvas> Rendering ● 2D primitive ○ path, curve, polygon ○ fill, stroke ○ image manipulation ○ pixel manipulation ● <canvas> primitive HW acceleraton ○ image manipulation ● <canvas> buffer itself is a GPU texture
  • 17. WebGL Rendering ● JavaScript wrapper of OpenGL
  • 18. Compatibility across Mobile Devices ● Not all of the rendering models can be used for mobile devices right now ● Compatibility summary ○ CSS 2D/3D (HW) ■ ICS 4.0 >, iOS 4.0 > ○ canvas (SW) ○ Android 2.3 <= ● canvas (HW) ○ Android 4.0 >, iOS 5.0 > ● WebGL ○ iOS 8.0 > ○ Android L >
  • 19. OS Distribution of Customers OK Cashbag App (June, 2014) the critical defect by Google
  • 20. General Rendering Back-end for Mobile Devices ● <canvas> 2D for Game object rendering ○ HW acceleration ● DOM for Game UI ○ 2D/3D by GPU
  • 21. App-embedded Branded Casual Game ● In-app play for user retention ● No app update via app store
  • 22. <canvas> based Game Development Browser limitations ● Browser engine as a game platform ○ rendering ■ <canvas>, WebGL, DOM ○ sound ■ <audio> ■ WebAudio ○ resource loading ■ XHR/<img> ○ input ■ touchstart, touchmove, touchend ○ DPI management ■ image resource scale up/down
  • 23. <canvas> based Game Development Into Reality ● The limitations of open source game engine ○ only for PC chrome/Firefox ○ does not meet the hard requirements for mobile OS ● In-house game engine development ○ to achieve stable 20 fps on our customer’s device ■ higher is better even on android 2.3 and iOS 5.0 ○ reasonable touch response delay ○ no garbage collection whiling playing ● Further information ○ http://www.slideshare.net/senxation/html5-ok-33344593
  • 24. <canvas> Game Main Loop ● As easy as animation by flipping pages
  • 25. Representaion of Game Objects ● Two approaches ○ static image generation: offline image based ○ dynamic image generation: drawing primitive combination based ● Each approach has its own pros and cons ○ performance ○ design-constraint
  • 26. Image based Object Representation ● A series of sprite image cropping/scaling ○ ctx.drawImage(src, dest) ○ the performance of game is decided by drawImage() ● Static image generation (offline) ○ one for each low, mid, high resolution devices
  • 27. Drawing Primitive Combination ● Dynamic image generation ○ draw an object onto a buffer with the prior knowledge of device DPI, target pixel dimension ○ minimize image scaling during rendering http://simeonvisser.hubpages.com/hub/HTML5-Tutorial-Drawing-Circles-and-Arcs
  • 28. Summary of Pros and Cons ● Image based (offline) ○ overall performance limited by image scaling primitive ○ designer-friendly ● Drawing primitive based (online) ○ higher performance ○ be an enemy to a developer with lower IQ ○ be an enemy to a designer
  • 29. Performance of <canvas> in Detail in WebView for Hybrid App ● The killing bottleneck is “PAINTING” ● Performance challenges ○ no <canvas> HW acceleration: android 2.3, iOS 4.0 ○ Kitkat Chrome Webview’s critical error by Google ■ no HW acceleration on 4.4, 4.4.2 Chrome Webview ■ fixed at 4.4.3 ■ but market share of 4.4.2 in Korea → 65%
  • 30. The Problem Definition when it comes to developing <canvas> game for mobile devices ● Android 2.3 without canvas HW acceleration ○ together with canvas acceleration ● Android /4.4[0-2]/ without canvas HW acceleration
  • 31. Performance Analysis of Kitkat Webview ● To find the performance limiting factors ○ painting size ○ the number of drawing primitive calls ○ DOM tree complexity ● System under test ○ Optimus G Pro (4.4.2) ○ Nexus 5 (4.4)
  • 32. Performan Analysis I ● Partial rendering ○ reuse the content of a previous frame buffer ● Full rendering ○ reset a frame buffer every rendering painting area size fps The Larger, The Slower
  • 33. Performance Analysis II ● Increase the number of painting areas ○ a painting area size is fixed to 25x25 fps the number of painting area
  • 34. Performance Analysis III ● Impact analysis with respect to DOM complexity
  • 35. Performance Analysis V ● Impact analysis with respect to DOM complexity ● Severe fps fluctuation
  • 36. Summary of Performance Analysis ● In proportion to the size of painting area, painting performance (fps) is decreased ● The more complex DOM tree containing <cavas> is, the more severely fps fluctuates
  • 37. Performance Improvement ● 5 practical techniques ○ DOM/<canvas> hybrid rendering for game objects ○ Static object pool for keeping garbage collector asleep ○ Smart repaint by tracing invaldated areas ○ Image resource offline manipulation ○ Minimize a DOM tree complexity ● not all of them are applicable at the same time ○ depending on game scenario, game performance requirement, smart repaint/hybrid rendering can be selectively applicable
  • 38. DOM/<canvas> Hybrid Rendering painting size minimization ● Selectively separate game objects contained in <canvas>, and then paint them through DOM canvas only canvas/DOM Hybrid
  • 39. DOM/<canvas> Hybrid Rendering implementation detail: DOM node pool ● Manage/reuse a set of DOM nodes with a background image of a game object
  • 40. Smart Repaint Repaint Region Trace ● Reuse the content of the frame buffer of n-1 frame for rendering n frame ● Trace the invalidated area, paint only invalidated area
  • 41. Source Image Size Matters A LOT! ● A sprite image is generally used to minimize # of network req ● Performance anomaly ○ the larger the source image is, the slower fps is, even when the destination size is fixed separate
  • 42. Garbage Collector Stops The World ● All objects are allocated from a object pool ● Implementation of a object pool matters ○ single Array, double Array, linked list ○ http://jsperf.com/objectpool-performance-comparison
  • 43. Static Object Pool Performance Comparision ● Single array by Array.push/pop is the best ○ poor performance of Array.spice() ● Complete suppression of GC is impossible
  • 44. Dive into Resolution Issue ● A designer-generated image is scaled up/down 4 times at most implicitly ○ canvas.width, canvas.height ○ canvas.style.width, canvas.style.height ○ ctx.drawImage(source, destination) ○ window.devicePixelRatio ● Try not to scale canvas.width/height, canvas. style.width/height ○ how to adapt device resolution in performant way ○ no fitting/add padding is good for performance ○ sub optimal display for a user
  • 45. <canvas> Isolation ● fps swing around 30% up and down, when <canvas> is contained within a document with complex DOM tree ● Seprate <canvas> from DOM based game UI ○ not easy in the real field where designers/publisher and developers from different teams are co-working
  • 46. Case Study: Flappy Ball ● DOM/<canvas> hybrid ● Smart repaint, sprite image separation
  • 47. 2048 ● DOM/GPU only ● Keeping GPU textures as long as possible
  • 48. Space 2014 ● Radically reuse a previous frame without clearance ○ Android 2.3 ● clearRect/fillRect
  • 49. Closing Remark ● For commercialization on mobile devices, performance matters a lot ○ understading Web-engine internals is essential for developing commercial level game successfully ● open sourced ○ http://skpla.net/bPqc