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