HTML5 Canvas Performance optimization

David Goemans
David GoemansProject Manager at Creative Clicks
May 2014
Overcoming the bottleneck of HTML5
canvas game performance
David Goemans
Moscow | 2014
About us
 BoosterMedia was founded in 2009 and is now
the leading HTML5 games company worldwide
 The BoosterMedia HQ is based in Amsterdam, with
offices in Tokyo, London, Singapore and São Paulo
 BoosterMedia runs 100+ white-label HTML5
channels for media companies, game brands, Telcos and
OEMs
 Reaching over 6 million HTML5 gamers every month
 Largest HTML5 games-catalogue: over 350 titles
available, new games are added on a weekly basis
 And in-house Game Studio for high-end HTML5
games
 Mobile Entertainment Awards Winner ’13
“Best mobile social games platform”
 BoosterMedia is backed by leading European VCs
100+ HTML5 Game stores for brands
1. Branded game stores 2. Lots of HTML5 games 3. Revenue generation
About me
David Goemans
6 years games industry experience, 8 years programming professionally
Until last year making indie games, mostly C++ and C#
Now, Lead Game Developer @ BoosterMedia, HTML5 & Javascript
There's a problem?
Device
100 Images
50x50px
5 Fullscreen
Images
iPhone 4 Safari 55 fps 30 fps
iPad 2 Safari 60 fps 50 fps
Samsung Galaxy S3 Internet 30 fps 25 fps
Samsung Galaxy S3 Chrome 50 fps 60 fps
Samsung Galaxy S4 Internet 30 fps 30 fps
Samsung Galaxy S4 Chrome 35 fps ??? 45 fps ???
Sony Xperia Z1 Chrome 60 fps 60 fps
Canvas Draw call and Fill rate benchmarks
WebGL is also no silver bullet! Canvas performance in the few
browsers that support WebGL is generally good, so it doesn't really
solve a problem.
iOS
iOS Generally works well, except...
 Fullscreen draw calls are often slow (especially on iPads)
 UIWebView is much slower with Canvas rendering than Safari
 Javascript calls in UIWebView are much slower than Safari
 All browsers other than Safari use UIWebView internally due to Apple's Policies.
 This means that Safari will always give the best performance.
Stock Android < 4.4
Android is a double edged sword
The stock Android browser is often compared to IE6. While it has far greater
standards support, what makes it potentially worse is that the OEMs control their
own implementations.
Samsung, LG and HTC devices all have slightly different stock browsers, all with
their own quirks and bugs. Sony gives you Chrome as the stock browser!
We've seen better Frame rates in Bubble Fever
on the Galaxy S2 than the Galaxy S4
Stock Android 4.4
Stock Android browser is normally built off the Android
Webview.
The WebView in Android 4.4 is being replaced by Chromium,
and many manufacturers have built their new browser on this.
In the long term this is great, but in the short term, it's bad.
Android 4.4 WebView doesn't support hardware accelerated canvas. This has been
fixed already and will probably make the next Android OS update. This leaves
HTML5 games in a bad situation for Android 4.4.
Windows Phone
WP 8 Deserves an honorable mention
 Almost everything works out of the box.
 Performance is good, still works on low end devices ( like the Lumia 520 )
 Some odd css/js standards issues, but we had similar bugs in Firefox
 IE Mobile behaves exactly like the Internet Explorer PC
Quick cheats that sometimes work
 Upscale as much as looks good
Cut down on translate()/save()/restore() calls! Often used when not needed.
 Use context.width = context.width to clear (except on the Galaxy S3 webview)
 Add 3d transforms to the body css
 Use Spritesheets to avoid texture swaps
 Be smart with your textures! Less draw calls == faster!!
 Spread text updates over a few frames. Text is slow!
 Don't draw if you don't have to (ie, if nothing has changed). Layers help!
Slow drawing performance
Fullscreen draw calls are slow and can be sped up using canvas layers
Even if you use an engine like Phaser, add your own canvas to draw behind the
stage canvas of the engine, and set the stage canvas to transparent.
Only draw things on the background layer when they need updates, use the main
layer for all moving things.
Lag spikes
Pooling with a default sized pool helped resolve most lag spikes. A pool is
basically an array with a set of pre-created objects. You can retrieve an unused
object from the list instead of creating a new one, and put back finished objects
instead of destroying them. By not destroying, there's no garbage. By pre-creating
multiple objects, you can cut down on object allocations.
 Identify when the spikes occur
 Work out what causes them with the profiler
 Normally it's creating a sprite/effect, switching a texture, or garbage collection
 Create a pool of the offending object.
Profile, profile, profile
 Chrome is your best friend!
 Profile on the desktop and on devices
 Use Canvas Profiler to see draw calls
 Use JavaScript CPU profiling to see
 Analyze the results to see what's eating up your CPU cycles
 Remember 1 frame @ 30FPS == 33ms. Every ms counts!
Show time!!
As chrome warns you...
We want your games!!
license@boostermedia.com
Twitter: @boostermedia
www.boostermedia.com
CONTACT US
Any technical questions?
david.goemans@boostermedia.com
Twitter: @dgoemans
www.boostermedia.com
Download this presentation:
link: http://is.gd/html5profiling
1 of 15

Recommended

High Performance Mobile Web Game Development in HTML5 by
High Performance Mobile Web Game Development in HTML5High Performance Mobile Web Game Development in HTML5
High Performance Mobile Web Game Development in HTML5Sangmin Shim
4.1K views61 slides
Idiot's Guide to viewport and pixel by
Idiot's Guide to viewport and pixelIdiot's Guide to viewport and pixel
Idiot's Guide to viewport and pixelNathan Campos
5.4K views16 slides
Introduction to Phaser.js by
Introduction to Phaser.jsIntroduction to Phaser.js
Introduction to Phaser.jsFrancesco Raimondo
1.1K views27 slides
Phaser presentation by
Phaser presentationPhaser presentation
Phaser presentationPatrick John Pacaña
705 views24 slides
How to fake a database/backend in Axure... and more by
How to fake a database/backend in Axure... and moreHow to fake a database/backend in Axure... and more
How to fake a database/backend in Axure... and moreSandra González
18.4K views49 slides
Extreme Javascript Minification by
Extreme Javascript MinificationExtreme Javascript Minification
Extreme Javascript MinificationDavid Goemans
3.2K views9 slides

More Related Content

Similar to HTML5 Canvas Performance optimization

Echo HTML5 by
Echo HTML5Echo HTML5
Echo HTML5Nathan Smith
74.6K views71 slides
HTML5 & JavaScript Games by
HTML5 & JavaScript GamesHTML5 & JavaScript Games
HTML5 & JavaScript GamesRobin Hawkes
7.5K views80 slides
The Future of Flash by
The Future of FlashThe Future of Flash
The Future of FlashChris Black
469 views40 slides
Angels versus demons: balancing shiny and inclusive by
Angels versus demons: balancing shiny and inclusiveAngels versus demons: balancing shiny and inclusive
Angels versus demons: balancing shiny and inclusiveChris Mills
3.3K views54 slides
Appcelerator Titanium Intro by
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium IntroNicholas Jansma
4.2K views22 slides
Phonegap - An Introduction by
Phonegap - An IntroductionPhonegap - An Introduction
Phonegap - An IntroductionTyler Johnston
47 views28 slides

Similar to HTML5 Canvas Performance optimization(20)

HTML5 & JavaScript Games by Robin Hawkes
HTML5 & JavaScript GamesHTML5 & JavaScript Games
HTML5 & JavaScript Games
Robin Hawkes7.5K views
The Future of Flash by Chris Black
The Future of FlashThe Future of Flash
The Future of Flash
Chris Black469 views
Angels versus demons: balancing shiny and inclusive by Chris Mills
Angels versus demons: balancing shiny and inclusiveAngels versus demons: balancing shiny and inclusive
Angels versus demons: balancing shiny and inclusive
Chris Mills3.3K views
Publishing HTML5 Games: It’s ShowTime! | Laurens Rutten by Jessica Tams
Publishing HTML5 Games: It’s ShowTime! | Laurens RuttenPublishing HTML5 Games: It’s ShowTime! | Laurens Rutten
Publishing HTML5 Games: It’s ShowTime! | Laurens Rutten
Jessica Tams434 views
Hacking the Kinect with GAFFTA Day 1 by benDesigning
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
benDesigning6.4K views
Adobe Flash - Past, Present and Future by Iain Lobb
Adobe Flash - Past, Present and FutureAdobe Flash - Past, Present and Future
Adobe Flash - Past, Present and Future
Iain Lobb2.3K views
Microsoft Webday 2008 - Silverlight Experiences by Nicklas Andersson
Microsoft Webday 2008 - Silverlight ExperiencesMicrosoft Webday 2008 - Silverlight Experiences
Microsoft Webday 2008 - Silverlight Experiences
Nicklas Andersson516 views
iOS vs android .pptx by abid masood
iOS  vs android .pptxiOS  vs android .pptx
iOS vs android .pptx
abid masood16 views
Responsive design and retina displays by Eli McMakin
Responsive design and retina displaysResponsive design and retina displays
Responsive design and retina displays
Eli McMakin8.7K views
Building Websites of the Future With Drupal 7 by Jay Epstein
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7
Jay Epstein3.1K views
Building Websites of the Future With Drupal 7 by Jay Epstein
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7
Jay Epstein2.4K views
Building an Open Source iOS app: lessons learned by Wojciech Koszek
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learned
Wojciech Koszek458 views
The near future of real web applications by X.commerce
The near future of real web applicationsThe near future of real web applications
The near future of real web applications
X.commerce431 views
ADOBE MAX 2006 - "Developing Flash Lite Games" Conference - by Didier Agani (... by Didier A
ADOBE MAX 2006 - "Developing Flash Lite Games" Conference - by Didier Agani (...ADOBE MAX 2006 - "Developing Flash Lite Games" Conference - by Didier Agani (...
ADOBE MAX 2006 - "Developing Flash Lite Games" Conference - by Didier Agani (...
Didier A3.8K views

Recently uploaded

Attacking IoT Devices from a Web Perspective - Linux Day by
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
16 views68 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
41 views73 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
26 views13 slides
Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
136 views15 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 views15 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide

Recently uploaded(20)

Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta26 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst478 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10248 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views

HTML5 Canvas Performance optimization

  • 1. May 2014 Overcoming the bottleneck of HTML5 canvas game performance David Goemans Moscow | 2014
  • 2. About us  BoosterMedia was founded in 2009 and is now the leading HTML5 games company worldwide  The BoosterMedia HQ is based in Amsterdam, with offices in Tokyo, London, Singapore and São Paulo  BoosterMedia runs 100+ white-label HTML5 channels for media companies, game brands, Telcos and OEMs  Reaching over 6 million HTML5 gamers every month  Largest HTML5 games-catalogue: over 350 titles available, new games are added on a weekly basis  And in-house Game Studio for high-end HTML5 games  Mobile Entertainment Awards Winner ’13 “Best mobile social games platform”  BoosterMedia is backed by leading European VCs
  • 3. 100+ HTML5 Game stores for brands 1. Branded game stores 2. Lots of HTML5 games 3. Revenue generation
  • 4. About me David Goemans 6 years games industry experience, 8 years programming professionally Until last year making indie games, mostly C++ and C# Now, Lead Game Developer @ BoosterMedia, HTML5 & Javascript
  • 5. There's a problem? Device 100 Images 50x50px 5 Fullscreen Images iPhone 4 Safari 55 fps 30 fps iPad 2 Safari 60 fps 50 fps Samsung Galaxy S3 Internet 30 fps 25 fps Samsung Galaxy S3 Chrome 50 fps 60 fps Samsung Galaxy S4 Internet 30 fps 30 fps Samsung Galaxy S4 Chrome 35 fps ??? 45 fps ??? Sony Xperia Z1 Chrome 60 fps 60 fps Canvas Draw call and Fill rate benchmarks WebGL is also no silver bullet! Canvas performance in the few browsers that support WebGL is generally good, so it doesn't really solve a problem.
  • 6. iOS iOS Generally works well, except...  Fullscreen draw calls are often slow (especially on iPads)  UIWebView is much slower with Canvas rendering than Safari  Javascript calls in UIWebView are much slower than Safari  All browsers other than Safari use UIWebView internally due to Apple's Policies.  This means that Safari will always give the best performance.
  • 7. Stock Android < 4.4 Android is a double edged sword The stock Android browser is often compared to IE6. While it has far greater standards support, what makes it potentially worse is that the OEMs control their own implementations. Samsung, LG and HTC devices all have slightly different stock browsers, all with their own quirks and bugs. Sony gives you Chrome as the stock browser! We've seen better Frame rates in Bubble Fever on the Galaxy S2 than the Galaxy S4
  • 8. Stock Android 4.4 Stock Android browser is normally built off the Android Webview. The WebView in Android 4.4 is being replaced by Chromium, and many manufacturers have built their new browser on this. In the long term this is great, but in the short term, it's bad. Android 4.4 WebView doesn't support hardware accelerated canvas. This has been fixed already and will probably make the next Android OS update. This leaves HTML5 games in a bad situation for Android 4.4.
  • 9. Windows Phone WP 8 Deserves an honorable mention  Almost everything works out of the box.  Performance is good, still works on low end devices ( like the Lumia 520 )  Some odd css/js standards issues, but we had similar bugs in Firefox  IE Mobile behaves exactly like the Internet Explorer PC
  • 10. Quick cheats that sometimes work  Upscale as much as looks good Cut down on translate()/save()/restore() calls! Often used when not needed.  Use context.width = context.width to clear (except on the Galaxy S3 webview)  Add 3d transforms to the body css  Use Spritesheets to avoid texture swaps  Be smart with your textures! Less draw calls == faster!!  Spread text updates over a few frames. Text is slow!  Don't draw if you don't have to (ie, if nothing has changed). Layers help!
  • 11. Slow drawing performance Fullscreen draw calls are slow and can be sped up using canvas layers Even if you use an engine like Phaser, add your own canvas to draw behind the stage canvas of the engine, and set the stage canvas to transparent. Only draw things on the background layer when they need updates, use the main layer for all moving things.
  • 12. Lag spikes Pooling with a default sized pool helped resolve most lag spikes. A pool is basically an array with a set of pre-created objects. You can retrieve an unused object from the list instead of creating a new one, and put back finished objects instead of destroying them. By not destroying, there's no garbage. By pre-creating multiple objects, you can cut down on object allocations.  Identify when the spikes occur  Work out what causes them with the profiler  Normally it's creating a sprite/effect, switching a texture, or garbage collection  Create a pool of the offending object.
  • 13. Profile, profile, profile  Chrome is your best friend!  Profile on the desktop and on devices  Use Canvas Profiler to see draw calls  Use JavaScript CPU profiling to see  Analyze the results to see what's eating up your CPU cycles  Remember 1 frame @ 30FPS == 33ms. Every ms counts!
  • 14. Show time!! As chrome warns you...
  • 15. We want your games!! license@boostermedia.com Twitter: @boostermedia www.boostermedia.com CONTACT US Any technical questions? david.goemans@boostermedia.com Twitter: @dgoemans www.boostermedia.com Download this presentation: link: http://is.gd/html5profiling