Open Lerg opened 3 years ago
I don't think WASM will optimize much in terms of speed here, as Heaps should run already well on modern JS VM because of the typed nature of Haxe which plays well with optimizer. Also, if your rendering is too slow it might be GPU related and not CPU related.
@ncannasse the problematic parts are CPU related - box2d physics and possibly dynamic autotiling. Box2D runs fine with WASM in other engines but in my case it has been rewritten in Haxe so I am not sure if it will be much slower but I hope not.
As hashlink can be embedded it is worth looking into WASM even if performance is the same as vanilla js.
I don't think HashLink can support WASM without changing the GC a lot. The collector currently scans registers and stacks, relying on setjmp
for the former. As per Emscripten portability guidelines:
Code that scans registers or the stack. This won’t work because a variable in a register or on the stack may be held in a JavaScript local variable (which cannot be scanned).
I've tried compiling Hashlink with emscripten, it compiled with a few adjustments.
When running the project it quickly fails with an exception when it gets to the C part, around hl_global_init() in hlc_main.c: too much recursion or stack is full.
More info with the sources and binaries here https://github.com/Lerg/hashlink-emscripten
I don't have much experience debugging WASM projects or understanding the underlying of Hashlink, but I hope it can run in a browser with a few fixes.
I need WASM because my work project based on Heaps is too slow when running the plain JS export.