3 Replies - 139 Views - Last Post: 28 January 2020 - 07:57 PM Rate Topic: -----

#1 ge∅   User is offline

  • D.I.C Lover

Reputation: 197
  • View blog
  • Posts: 1,198
  • Joined: 21-November 13

Javascript to WebAssembly with Unity/Unreal? and thoughts on Wasm

Posted 27 January 2020 - 05:10 PM

Hello,

I am developing this game in the browser and I have these CPU intensive tasks (they take several seconds in a different thread to compute). I was wondering if converting some of my code to WebAssembly would provide any benefit? I have already improved the performance of my app a lot but I have the feeling I will soon be reaching the limit of what I can do and it may not be enough.

The idea I'm having is that these game engines support a subset of Javascript and have a WebAssembly output, so if I can have them digest my JS and package only the things I need for my code to run to WebAssembly, it could be a way to get a free performance boost, maybe enough to meet my performance requirements.

The questions that remain:

- Could the just-in-time compilation of my Javascript in the browser be already equivalent to what WebAssembly would offer me on my code? (because JS doesn't have strong typing or fixed-length arrays for example, how could it be further optimised?). I don't know C/C++. Some of my code would probably be simple enough to rewrite (arithmetic on large arrays for example) but if I could compile larger chunks of code, complete logical units, without having to rewrite them, it would be preferable.

- What's the cost of sending/retrieving data to and from a WebAssembly module ? Do you think WebAssembly would be interesting to use in individual functions (in the same fashion that, for example, the methods of the Math object run native code when you call them: Javascript's Math.abs() for example is not implemented in Javascript - I would do this on bigger functions though, but you see what I mean)?

- I have never used Unity/Unreal. Is there something I misunderstand about their WebAssembly publishing feature which makes my question stupid?

Thank you for your attention ;)

Is This A Good Question/Topic? 0
  • +

Replies To: Javascript to WebAssembly with Unity/Unreal? and thoughts on Wasm

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: Javascript to WebAssembly with Unity/Unreal? and thoughts on Wasm

Posted 27 January 2020 - 05:48 PM

To make sure I have this correctly.

You are making a browser based game, and not using an engine of any sort.,

You are looking at offloading JS functions into WebAssembly.

You are looking at using Unity, or Unreal, as some sort of compiler IDE to spit out the webassembly, but not use them as a full engine.

Does that lay it out?

https://www.smashing...-speed-web-app/
Was This Post Helpful? 0
  • +
  • -

#3 ge∅   User is offline

  • D.I.C Lover

Reputation: 197
  • View blog
  • Posts: 1,198
  • Joined: 21-November 13

Re: Javascript to WebAssembly with Unity/Unreal? and thoughts on Wasm

Posted 28 January 2020 - 07:15 PM

Yes it does.

I just installed Unreal Engine and the plugin Unreal.js which includes a V8 runtime.
I have tried to publish an empty project and got a 50 megabyte .wasm file (alongside a 30 megabytes .data file) so I take it the whole game engine is included. There doesn't seem to be a way to export a single module contrary to what I had read (unless I am confusing with Unity).

Learning the basics of each game engine and running tests could take a lot of time for no benefit, which is why I am asking here first. I am not even sure the game engine is not simply going to output the Javascript as "text" when I publish as HTML5, and offload the compilation to the browser as usual (it would only be compiling the engine code and interacting with it in JS), because there may not be a lot of sense in implementing a Javascript to WebAssembly compiler in the first place.

This post has been edited by ge∅: 28 January 2020 - 07:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15493
  • View blog
  • Posts: 62,050
  • Joined: 12-June 08

Re: Javascript to WebAssembly with Unity/Unreal? and thoughts on Wasm

Posted 28 January 2020 - 07:57 PM

Unity and Unreal are not like Visual Studios. They are not an independent IDE to compile with. They are there to build game bits into their game engine.

You can always pop into github, or a tutorial, for the relevant engine, compile it, and see the output.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1