Hi all,
I would like to gather some feedback on loading times. It would be great if you could share some numbers, especially regarding asm.js vs wasm (regular build versus WebAssembly) on different browsers.
Regarding WebAssembly, keep in mind that browser vendors are still working on improvements, in fact you might notice differences if you run their latest versions: for example Chrome Canary build instead of latest stable Chrome (at this time, version 63 and 61 respectively).
Here is some code you can use to measure loading times:
where “Loading time” is the aggregate download+instantiation and Unity engine initialization.
One note about Chrome, keep the DevTools closed while loading the page as I noticed that might affect loading times. In addition, remember to test using 64-bit versions of the browsers.
I’ll take this opportunity to summarize some best practices to reduce load times:
reduce code size
reduce data size
use gzip/brotli compression
enable compression support for .unityweb files on your server
make first scene small
I think these items have been discussed before so I am not going to add more detail but feel free to ask questions.
Thanks,
Marco
I’ll try to push our test “loading project” to the cdn to share, but those findings roughly line up with what we observe. One thing you might want to note is that chrome doesn’t do AOT compilation for javascript/asm.js but does for wasm (I think eventually they plan to convert asm.js to wasm, but for now…). Thus if your primary bottleneck is the cpu, you can gain a decent performance boost by utilizing wasm on chrome.
Have you guys tested Edge (which will enable wasm by default for the fall creator’s update) and Safari (which also enables wasm by default for version 11)? I’m curious about your findings for those platforms.
Regarding 4th tip, enable compression support for .unityweb files on your server
I found out even I didn’t set anything on server(aws), it still uses gzip ( by logging in compress function in gzip in UnityLoader.js), in the code I found out it checked for data[0] and data[1] to see if it is certain value to determine if using gzip
I refreshed the browser a few times for each and took the fastest time. I also got these times from a webserver on my computer so download time is not a factor.
Unity version used to build this project is 2017.1.1f1.
Unity build settings: Non-development, 1024 memory size, explicitly-thrown exceptions only, gzip compression, debug symbols checked.
Computer: Windows 10 x64 i7-6800k 32gb ram
If anyone from the Unity team would like to see my project, let me know and I can provide it.
Thanks for this script! We have these times for our project, built on 2017.1.0p4, and run on a i7-4790:
Chrome (62) :
ASM :
Download+Instantiation time: 8861 ms
Engine initialization time: 5940 ms
Loading time: 14801 ms
WASM :
Download+Instantiation time: 11478 ms
Engine initialization time: 3558 ms
Loading time: 15036 ms
Firefox (56) :
ASM :
Download+Instantiation time: 1637 ms
Engine initialization time: 7550 ms
Loading time: 9187 ms
WASM :
Download+Instantiation time: 3043 ms
Engine initialization time: 7662 ms
Loading time: 10705 ms
This is tested on a local server, so there is almost no download time. Clearly WASM is not worth it for our project right now. Any idea where this might come from? We have a memory size of 768MB.
It sounds like on Chrome you will benefit a lot from the compiled WebAssembly caching we are working on. At least, that will speed up hot-reload by several seconds.
however, it’s possible to store the compiled wasm into IndexedDB, so that the second time you open the same web page containing a wasm-enabled Unity build, you can skip #1 and #2.
This is something we are implementing right now and you won’t need to make any change to your project, apart from re-building.
That sounds great! I’d love to hear before/after numbers for how much this decreases repeat load times. I’d also love to run my project through it once a preview becomes available, just to know how much that would help.
Right now I’m at the point where I’m trying to decide if I want to port my game into native Javascript, since my customers are regularly experiencing 30+ second load times trying to load Unity and I’ve exhausted all other options to speed it up. So knowing how much the caching will speed it up will help me make that decision.
That’s awesome!
We are currently working on a system to split a lot of our application into asset bundles, to speed up the “first draw” time. I’ll probably repost results of the difference between ASM and WASM when we have something working.
I should also mention a couple more optimizations that will speed up load times when the compiled wasm has not been cached yet. The first one is wasm tier-ed compilation (fast baseline + additional compilation passes for hot-paths). The other one is wasm streaming compilation which will allow wasm to be compiled while it is downloaded, especially useful for large code-bases. The former will be available to you as soon as it’s implemented by the browsers and will speed up existing wasm-enabled content. The latter requires both support in Unity and in the browsers, therefore it will take a bit longer before you can use it and it will need the Unity project to the re-deployed.
I’d like to take advantage of caching the content, however I work on an enterprise-oriented application with continuous releases. Is there a preferred method of invalidating a client’s cache? Query strings aren’t ideal…