Why is my game so much slower on WebGL than on desktop?

I’ve made a benchmark program that does various operations, mostly running Mini Micro code (which is implemented as plain old C# code). Running this in the WebGL build, on the very same MacBook Pro as the desktop build, everything takes substantially longer:

And this doesn’t seem to have anything to do with graphics per se; some of the worst offenders (Semiprime and Race Sim) generate no output at all while they’re cranking away. It’s all just math and looping.

Any idea why the same code running on the same hardware should be 2-4 times slower in a WebGL build?

C# vs Javascript…?

Doesn’t Unity compile to web assembly? Or is it still building to JS? (This was made with Unity 2018.2.2 in case that matters.)

I’ve been assuming web assembly’s VM is not so different from C#'s VM in terms of performance, but maybe that’s not true. I should have also mentioned the browser I was testing in (Firefox), and I guess I should test with other browsers, in case not everyone’s webasm is created equal.

1 Like