Boost the Performance of Your WebGL Unity Games!

Rate this content
Bookmark

Unity, when deployed on the web, faces three critical challenges: build size, memory usage, and overall performance. This lecture delves deep into advanced optimization techniques to help you address each of these issues. Attendees will gain insights into:


- Effective strategies for optimizing textures, audio, and models.

- A detailed analysis of our ASTC experimentation with Unity, shedding light on the unexpected results despite Unity's claims.

- A comprehensive guide to Unity's memory profiling tool and its implications.

- An exploration of lesser-known Unity settings that remain underutilized by many developers.


Additionally, we'll introduce our proprietary tool designed specifically for Unity optimization. We will also showcase CrazyGames' developer dashboard, our platform that enables developers to monitor and enhance the performance of their web-based games seamlessly. 


Join us to equip yourself with the latest strategies and tools to elevate your Unity web gaming projects.

This talk has been presented at JS GameDev Summit 2023, check out the latest edition of this JavaScript Conference.

FAQ

Brotli and jZip are two compression formats used for Unity WebGL builds. Brotli is generally recommended because it takes up less space compared to jZip, which is important as games get larger.

Choosing the right texture compression format, like DXT for desktops and ASTC for mobile browsers, helps keep textures compressed in memory, reducing runtime memory usage and potentially improving performance.

Unity provides tools like the Profiler for identifying performance and memory issues. Additionally, the Memory Profiler package offers detailed analysis, and the optimization tool available on GitHub or Unity Asset Store helps optimize assets and analyze build logs.

Low runtime memory usage is crucial because Unity uses a memory heap to store game data in the browser. Excessive memory usage can lead to a browser being unable to allocate more memory, causing the game to crash.

Common issues include bundle size, memory usage, and runtime performance. These factors influence how fast the game loads, the RAM usage, and overall game performance.

Asset bundles and addressables allow developers to separate certain assets (like textures and audio) into different files that are loaded only when needed, effectively reducing the initial load size of the game.

Developers should avoid full exception support to minimize impact on bundle size and performance. If try-catch is necessary, using explicitly thrown exceptions is advised.

Florin Ciornei
Florin Ciornei
7 min
28 Sep, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The Talk discusses ways to boost the performance of WebGL Unity games, including issues with bundle size, memory usage, and runtime performance. It suggests using Brotli for compression and non-exception support for better performance. Choosing the appropriate texture compression format and experimenting with separate builds can also help. The Talk also covers optimizing textures, models, audio, and assets by reducing build size, using compression, disabling unnecessary models, and optimizing audio quality. Unity's optimization tools and profilers are recommended for analyzing performance and memory issues.

1. Boosting Performance of WebGL Unity Games

Short description:

I'll talk about boosting the performance of your WebGL Unity games. Unity web issues include bundle size, memory usage, and runtime performance. Brotli is recommended for compression due to its smaller size. Use non-exception support for better performance, but avoid full exceptions to reduce bundle size. Choose the appropriate texture compression format to save runtime memory. Experimentation with separate builds showed negligible improvements.

Hey, everyone, my name is Florin, and I'll talk today about boosting the performance of your WebGL Unity games. So a little bit about me. I'm a product engineer at Crazy Games, I'm also a game developer. You can see a couple of the games I created here. I mostly work with Unity, but I also do have some simple vanilla JS games.

At Crazy Games we're one of the biggest gaming platforms, we have more than 5000 games, we work with more than 700 developers and we also have 20 million of unique players. So yeah, let's start with the Unity web issues that you may encounter when building for the web. So there is the bundle size, it affects how fast your game loads, the memory usage, the RAM that basically your game uses when it runs, and the runtime performance. And why it's important to keep runtime memory usage low? Well, in the browser, Unity uses a memory heap to store the game data. And let's say you load a new scene, new textures need to be loaded, the browser may have to increase the heap size. And if a browser fails to allocate more memory to increase the heap size, you'll get this ugly popup that just crashes your game.

About the code performance, I won't talk about it here, so Oz already gave an excellent presentation about it, it's called Detect and Avoid Common Performance and Memory Issues in Unity WebGL and I encourage everyone to check it. About Brotli and jZip, these two are two different compression formats for the build in Unity. First of all, they don't ever launch uncompressed builds because they take around 11MB, the jZip, the default one, takes a little bit more space than the Brotli, so that's why we usually recommend the developers to pick the Brotli one, because you can see the difference, it may be quite small in an empty project, but when your game gets bigger, this difference will only get bigger. So yeah, usually stick with the Brotli one, although it takes a little bit more time to compress, but that's worth it.

About the exception support, so when you build a game for the web, you can pick the non-exception support, this is more performant, but you can't use try-catch anymore in your code. If you know that you have to use try-catch somewhere, pick the explicitly thrown exceptions only, which I think is also the default. And usually, you should avoid the full ones, except if you are debugging the game, because it will negatively affect the bundle size and performance of your game. I'd also like to talk about the texture compression format, which you can pick. Dext is the default one and this one is better for the desktop browsers. There is also ASTC that's better for mobile browsers and some Chromebooks. And if you pick the proper compression format, the textures don't have to be decompressed in memory and the game will use less runtime memory. You can see here in this small memory snapshot, we have a build with six textures, all of them quite big, and if they are decompressed in memory, they'll take around 75 megabytes. If they stay compressed, they take around 10 megabytes. So basically you managed to save around 65 megabytes of runtime memory, that's quite a lot on a mobile device. We tried to experiment this also with a couple of our games. Sadly, we only got some negligible load rate and load time improvements. And how we did it, we have two separate builds, and we either load the DXT one on all platforms or we smartly load this one to test on the necessary platform. And as we said, we didn't get any considerable improvements, but still, if you have, for example, a game that you launch only for mobile devices, consider to use this one, for example. Or you can check on Unity documentation how to load two separate builds, how we did with this experiment.

2. Optimizing Textures, Models, Audio, and Assets

Short description:

Pay attention to the max size of textures to reduce the build size. Consider using crunch compression for DXT and ATCM formats. Disable models that don't need to be high quality. Choose compressed memory for background audio and decompress and load for audio effects. Lower the quality of background audio to reduce the build size. Use Unity's optimization tool and build log analyzer. Consider using Asset Bundles or Unity's Addressables package to decrease initial load size. Use the Profiler and Memory Profiler tools to analyze performance and memory issues.

About the texture options. So pay attention at max size here, because you should keep this as low as possible on WebGL to reduce the final build size. If you reduce it, this will also reduce the texture size in the final build. You can also consider using crunch compression, it will help decrease also the bundle size, but it works only for these two texture compression formats, DXT and ATCM. It may take a little bit more time to build the game because the compression time will be increased, but the decompression is pretty fast when you start the game.

About the models, just in case you enabled this one, keep in mind that now the model needs to be kept in the runtime memory usage, so it's better to keep it disabled, I think by default it's also disabled. And also check if you can increase the mesh compression to high, for example, because you may have, let's say, a mountain in the distance that doesn't need to be high quality.

About the audio, if you pick compressed memory, that's usually good for background audio. It reduces the runtime memory usage, and background audios are usually some music loops that take quite a lot of memory. But this may reduce a little bit the latency and cause some imprecise audio play. Decompress and load, it's better for audio effects because you can keep them decompressed in memory. They usually don't take so much space, but they need to be precise when they're played. Also consider lowering the quality for background audio, because this may considerably reduce the audio size in the final build. Our optimization tool that you can grab on GitHub, or Unity Asset Store, and it also comes in our SDK, offers you all these tabs, they'll help you optimize your assets. It also offers build logs analyzers. For those who don't know, Unity usually generates a build log when you build a project, and it's an ugly, text-y file, log file, but this tool will beautify it a little bit and show you in a more readable way all the assets. And you can have a final look at all the assets that ended up in your final build. About Asset bundles and other symbols, consider using them because they help decrease the initial load size. How they work, they basically extract the textures, for example audio, some objects in a separate file that gets loaded only when it's needed. And you can do it with Asset Bundles which is low-level, you just fetch the file and extract the assets from it, but Unity now has an Addressables package that builds on top of Asset Bundles and it's much easier to use. You can see here an example of a game that uses Addressables and the initial build size for the build folder is around 17 megabytes. The StreamingAssets folder will be loaded later when needed, it's around 16 megabytes. So the developer managed to save around 16 megabytes from the initial game load.

I can't finish this presentation without talking a little bit about the integrated Profiler tool, which I think everyone should use to spot the performance issues and the memory issues. But for memory issues, if you want a little more detailed overview, there is a new package from Unity called Memory Profiler tool. It will help you capture snapshots of your running game, it can also connect directly to WebGL, and then it helps you analyze the textures for example of audio in the runtime memory.

That was all from my side, thank you for listening to it, and don't hesitate to check our documentation where we have more tips for Unity. And you can also contact us at developerrelations at crazygames.com. And we're looking forward to seeing your games on crazygames.com.

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 2022React Advanced 2022
25 min
A Guide to React Rendering Behavior
Top Content
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize 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
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
Watch video: Optimizing HTML5 Games: 10 Years of Learnings
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.
How React Compiler Performs on Real Code
React Advanced 2024React Advanced 2024
31 min
How React Compiler Performs on Real Code
Top Content
I'm Nadia, a developer experienced in performance, re-renders, and React. The React team released the React compiler, which eliminates the need for memoization. The compiler optimizes code by automatically memoizing components, props, and hook dependencies. It shows promise in managing changing references and improving performance. Real app testing and synthetic examples have been used to evaluate its effectiveness. The impact on initial load performance is minimal, but further investigation is needed for interactions performance. The React query library simplifies data fetching and caching. The compiler has limitations and may not catch every re-render, especially with external libraries. Enabling the compiler can improve performance but manual memorization is still necessary for optimal results. There are risks of overreliance and messy code, but the compiler can be used file by file or folder by folder with thorough testing. Practice makes incredible cats. Thank you, Nadia!

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.
How to make amazing generative art with simple JavaScript code
JS GameDev Summit 2022JS GameDev Summit 2022
165 min
How to make amazing generative art with simple JavaScript code
Top Content
WorkshopFree
Frank Force
Frank Force
Instead of manually drawing each image like traditional art, generative artists write programs that are capable of producing a variety of results. In this workshop you will learn how to create incredible generative art using only a web browser and text editor. Starting with basic concepts and building towards advanced theory, we will cover everything you need to know.
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.