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.
Comments