JavaScript Start-Up Performance, does it matter or is wasm the rescue?

Hey!

Today I read an interesting article about JavaScript start-up performance. I know one can not compare a regular Unity Game with an average website but the problems described in this article hit us really brutal with Unity WebGL. You can find the article here: JavaScript Start-up Performance. Update: The Cost Of JavaScript In 2019… | by Addy Osmani | reloading | Medium

Now I wonder, will there be improvements on JavaScript start-up performance or is WebAssembly the solution to all our problems? Is there work going on on improving JavaScript (asm.js) performance or does Unity wait for WebAssembly?

Do you think WebAssembly is stable enough to use it in production? As far as I know the current state of the WebAssembly standard is “Release Candidate”.

Will WebAssembly builds be significantly smaller (better code stripping etc)? Right now our builds are 22MB and about 5.5MB gzipped.

wasm is supposed to improve performance / loading times but we are not just waiting for that to happen.
For example, we are working on the modularization of the engine so that if a game does not use a specific feature, the code for that feature will not included in the build. This is something we already do now but can still be improved. Basically by reducing code size, we also improve loading times.
In addition, we are working on cross-platform optimizations for loading times and we expect WebGL to benefit from them as well.

That does not mean it’s ready for production :slight_smile:
Browser vendors still need to finish their implementation of the runtime and enable it by default. When that happens, assuming there are no other issues, we could say it’s ready for production.

I guess, from a user perspective it depends on your timeline. Depending on when you are planning to release, then your content might benefit from wasm. Having said that, keep in consideration that wasm support in Unity 5.6 is an experimental feature.

At this time we don’t have numbers to share yet as we 5.6 is still in Beta.

@Marco-Trivellato Thanks for your response. Sounds great, so interesting times are coming :slight_smile:

I think the “code stripping” feature works quite well. Our main problem is the PhysX library. When we only use a tiny bit, the whole library ends up in our build. This is a real pain. Will it be feasible to do “code stripping” inside the PhysX library?

Also I wanted to ask if it will be possible to “lazy load” code in the near future or do you think this makes no sense when WebAssembly arrives (due to smaller and more performant builds)?

Not really, If you build your game without using any asset bundle, then yes it work.
But if like me you build your game with a simple scene( in order to reduce the size) and then load the rest by using asset bundle, the code stripping do not help.

The only way, it’s to add all componants used by the asset bundle on the simple “Starting” scene but i don’t like this idea.

A simple listbox where we can check/uncheck what we need from the engine is the solution for me but it seem that the unity staff want track dependency on the asset bundle for the futur version.

Sound like new bug will come …

Any update on WASM in U2017.2, I see it’s still marked as experimental, any idea when that might change?
Is it actively being worked on or is it a case of just waiting for the browser vendors?

We’ve been using it since 5.6.x without any major issues (some workflow changes). All the browsers support wasm now too (Can I use... Support tables for HTML5, CSS3, etc).

There isn’t anything new (apart from a few bug-fixes) in regards to WebAssembly in 2017.x and the next update(s) will come in the 2018.x cycle.

It is being worked on and, actually, the plan is to deprecate asm.js, making WebAssembly the only supported format.

Good to hear that! Our tests are clearly showing us that WASM is superior compared to asm.js both in speed and stability. Right now 50% of crash reports we get are asm.js exclusive. We are even thinking about blocking asm.js by us. But our case is different than common unity projects, and our support policy is very restrictive (we support only ff and chrome as first class browsers).

Deprecating old standards is always beneficial even if it’s painful at the beginning.