4 ms·
I've experienced a 2x speedup when porting tight loops from JS to WASM. In my case, my tasks are decompression and texture decoding. I initially ported to C, an
by Jasper_ 6y ago
I've experienced a 2x speedup when porting tight loops from JS to WASM. In my case, my tasks are decompression and texture decoding. I initially ported to C, and then ported to AssemblyScript, being careful to manually manage the memory along the way.
The old code was also very "tight-loop" code that's just math, and no GC allocation, so it's not applicable to many people here yet, and it's possible that JS interpreters have improved since when I ported (GC behavior has gotten quite noticeably better in V8 in the last two years), but I'll take the speedups I can get.
For comparison:
Old TypeScript: https://github.com/magcius/noclip.website/blob/master/src/Common/Compression/Yaz0.ts#L25-L67 https://github.com/magcius/noclip.website/blob/master/src/Co...
New AssemblyScript: https://github.com/magcius/noclip.website/blob/master/src/assembly/Yaz0_as.ts https://github.com/magcius/noclip.website/blob/master/src/as...
Wrapper for WebAssembly execution: https://github.com/magcius/noclip.website/blob/master/src/Common/Compression/Yaz0.ts#L80-L102 https://github.com/magcius/noclip.website/blob/master/src/Co...