Optimizing HTML5 Games: 10 Years of Learnings

Rate this content
Bookmark

The open source PlayCanvas game engine is built specifically for the browser, incorporating 10 years of learnings about optimization. In this talk, you will discover the secret sauce that enables PlayCanvas to generate games with lightning fast load times and rock solid frame rates.

Will Eastcott
Will Eastcott
33 min
08 Apr, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

PlayCanvas is an open-source game engine used by game developers worldwide. Optimization is crucial for HTML5 games, focusing on load times and frame rate. Texture and mesh optimization can significantly reduce download sizes. GLTF and GLB formats offer smaller file sizes and faster parsing times. Compressing game resources and using efficient file formats can improve load times. Framerate optimization and resolution scaling are important for better performance. Managing draw calls and using batching techniques can optimize performance. Browser DevTools, such as Chrome and Firefox, are useful for debugging and profiling. Detecting device performance and optimizing based on specific devices can improve game performance. Apple is making progress with WebGPU implementation. HTML5 games can be shipped to the App Store using Cordova.

1. Introduction to PlayCanvas and Game Optimization

Short description:

Hi, my name's Will Eastcott. I'm the creator of PlayCanvas. Today, I'll be talking about optimizing HTML5 games based on 10 years of experience with the PlayCanvas game engine. PlayCanvas is an open-source game engine written in JavaScript and based on WebGL. It includes a browser-based visual editor for real-time collaborative game development. It powers Snap Games in Snapchat and is used by game developers worldwide for various types of games. My journey in game optimization began with Renderware, a game engine used in the PlayStation 2 generation. HTML5 game developers now have powerful hardware and built-in tools, but optimization is still crucial, focusing on load times and frame rate optimization.

♪ Hi, my name's Will Eastcott. I'm the creator of PlayCanvas. And I'm going to be talking to you today about optimizing HTML5 games based on 10 years of learnings working on the PlayCanvas game engine.

So to begin with, I want to just start by explaining a little bit about what PlayCanvas is. It's an open-source game engine. It's written in JavaScript. It's based on WebGL. And you also get this visual editor that's like browser-based. It's real-time collaborative. It's built in the cloud. So yeah, you can visually build your games in this editor.

So PlayCanvas actually powers Snap Games, which is the gaming platform in Snapchat. It's had over 200 million players. There's a large number of games that you can check out of just about any genre, so I would encourage you to check them out. But PlayCanvas isn't just used by Snapchat-based game developers. It's used by game developers the world over to make all sorts of different types of games, from casual games to .io games. It's actually pretty popular for FPS game developers, and you can see several of those represented there.

Now, my personal journey in working on game optimization started in the early 2000s working for a company called Criterion Software on a game engine called Renderware. Now, Renderware was used to power about a third of the games in the PlayStation 2 generation, and day-to-day I would be working on this type of hardware. So we're talking a T-10,000 PlayStation 2 developer kit. And yeah, if you wanted to do performance analysis on that kind of hardware, you would struggle. And you would often need to go into Sony's HQ and work on special hardware that was developed by then, very expensive hardware. It was incredibly inconvenient.

Fast forward to 2022, and HTML5 game devs are living the dream, right? I mean, we've got incredibly powerful hardware in the palms of our hand. And we've got great tools that are built right into our web browsers. So is optimization still important? Well, spoiler alert, yes it is. Now, performance optimization, in my view, falls into two main areas. There's load times, and there's also frame rate optimization. And let's start talking about load times. Now, this is something that we don't want our end users to see, loading bars.

2. Investigating Load Times and Texture Optimization

Short description:

So why does it matter whether we present our users with loading bars? After 6 seconds of waiting, we tend to lose 40% of our audience. To investigate load times, we can use advanced tools built into the browser, such as Chrome DevTools. By sorting resources based on size, we can identify opportunities for optimization. In HTML5 games, most of the data is texture-based, and large images can cause crashes and long load times. However, hardware texture compression can help by reducing GPU memory usage and eliminating decode costs.

So why does it matter whether we present our users with loading bars? Well, as it turns out, after 6 seconds of waiting, we tend to lose anything like 40% of our audience who just bounce, not prepared to wait for the page to load.

So when we begin an investigation into load time, what kind of tools do we have available to us that can help us investigate optimizing load times? Well, like I said, built right into the browser, you have some pretty advanced tools. In Chrome DevTools, you have a couple of tabs. You have the Networking tab, which shows you what resources My Game is loading, and then you have the Performance tab that shows how My Game is loading those resources. So when you start your investigation, you typically look for the low hanging fruits. If you look in the bottom left of the Browser tab, you'll see the number of requests made by the browser. You'll see the amount of data that's transferred, and you'll see the time it takes to load your game. Now, the first thing that you'll want to do is sort the list of resources based on size, because, obviously, the bigger the resource, the bigger the opportunities for optimization. You can search for duplicates or redundant resources that your game shouldn't really be loading in the first place. And if we look at the biggest file that's being loaded here into our game, it's a 2.2 megabyte jpeg. So we can ask ourselves, hey, can we downsize these resources? Can we optimize them somehow?

Now, as it turns out, in HTML5 games, typically most of the data tends to be texture-based data. And in our example in the previous slide, we had a 2.2 megabyte jpeg. Now, if the browser downloads this file, we need to decompress it into memory. And that is 48 megabytes of data. Then we have to pass it to WebGL to be used as a texture. And a copy of it is made, plus, we have to generate mitmaps, which is another 64 megabytes of data. So together, that's like 112 megabytes of data just for a single jpeg. Now, if you try to load about 10 of these into a browser tab on mobile, I guarantee you you'll crash the tab. So we need some kind of solution around this. Moreover, every jpeg reload, we have to pay, like, a decode cost. It takes time to actually decompress the data from jpeg to an uncompressed format. And in this case, this 2-megabyte texture takes 160 milliseconds, which is just excessive. Because it's going to cause the mainframe to block, and it's going to cause long load times. Luckily, we have hardware texture compression that we can use to load more optimized texture data. So if we take our original 2.2-megabyte jpeg and we crunch that down to some natively supported hardware texture formats like DXT, PVR, and ETC, we find that the sizes are actually larger than the original jpeg. So because the format of this hardware texture compression data is native to the GPU, we can just supply it to the GPU with no decode cost, which is great. Also, the amount of GPU memory used by hardware texture compressed data formats is between 1 5th and 1 10th of the original jpeg. So we're at least sure we're not going to be crashing the browser tab anymore. But we are paying the costs for having to download large images. And that's a problem.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
Top Content
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
Building Fun Experiments with WebXR & Babylon.js
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Building Fun Experiments with WebXR & Babylon.js
Top Content
During this session, we’ll see a couple of demos of what you can do using WebXR, with Babylon.js. From VR audio experiments, to casual gaming in VR on an arcade machine up to more serious usage to create new ways of collaboration using either AR or VR, you should have a pretty good understanding of what you can do today.
Check the article as well to see the full content including code samples: article. 
Power Fixing React Performance Woes
React Advanced Conference 2023React Advanced Conference 2023
22 min
Power Fixing React Performance Woes
Top Content
Next.js and other wrapping React frameworks provide great power in building larger applications. But with great power comes great performance responsibility - and if you don’t pay attention, it’s easy to add multiple seconds of loading penalty on all of your pages. Eek! Let’s walk through a case study of how a few hours of performance debugging improved both load and parse times for the Centered app by several hundred percent each. We’ll learn not just why those performance problems happen, but how to diagnose and fix them. Hooray, performance! ⚡️

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Make a Game With PlayCanvas in 2 Hours
JSNation 2023JSNation 2023
116 min
Make a Game With PlayCanvas in 2 Hours
Top Content
Featured WorkshopFree
Steven Yau
Steven Yau
In this workshop, we’ll build a game using the PlayCanvas WebGL engine from start to finish. From development to publishing, we’ll cover the most crucial features such as scripting, UI creation and much more.
Table of the content:- Introduction- Intro to PlayCanvas- What we will be building- Adding a character model and animation- Making the character move with scripts- 'Fake' running- Adding obstacles- Detecting collisions- Adding a score counter- Game over and restarting- Wrap up!- Questions
Workshop levelFamiliarity with game engines and game development aspects is recommended, but not required.
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
PlayCanvas End-to-End : the quick version
JS GameDev Summit 2022JS GameDev Summit 2022
121 min
PlayCanvas End-to-End : the quick version
Top Content
WorkshopFree
João Ruschel
João Ruschel
In this workshop, we’ll build a complete game using the PlayCanvas engine while learning the best practices for project management. From development to publishing, we’ll cover the most crucial features such as asset management, scripting, audio, debugging, and much more.
React Performance Debugging
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)