Experiment with particles using WebAssembly and WebGL
maierfelix.github.io
maierfelix.github.io
Quite interesting to read. I don't know much about WASM but I presume the big Uint8Array is the actual C program or something?
Same behavior observed here too.
I’m aware, thanks. I tested in both anyway just to have more data.
All demos I saw only gives 8-10x performance boost?? (with respect to JS)
As with any language, it depends on how good the optimizations are; wasm is designed to be able to be JITted fast, but is still fairly new, so there's still stuff left on the table.
Additionally if you're compiling a language to wasm, you're also at the mercy of that compiler as well, so it always depends.
> only 8-10x performance boost
I'll take it ;)
and potentially runtime, depending on the language you are compiling from
Frankly, I would be surprised to see well-written Javascript code that's consistently 8x to 10x slower than (single-threaded, non-SIMD) native performance. You have spikes from GC and re-compilation, but JITed JS is not that slow.
... is it ? tech demos ten years ago were already north of 1 million particles.
How does it work? What sort of VM is it running on? How is it compiled?
Here's a 2014 Unreal Engine asm.js demo now running on WASM:
https://s3.amazonaws.com/mozilla-games/ZenGarden/EpicZenGard...
It's running on your browser's JavaScript VM (maybe in a special mode). The code compiled to WASM just like any other machine language. Quite a few compilers support WASM as a target now.
Direct link to the game: https://www.funkykarts.rocks/demo.html
Blog post on porting the engine: http://www.rossis.red/wasm.html
Original thread: https://news.ycombinator.com/item?id=14411328
His post helped me demystify what WASM is capable of and how it fits with the DOM. He shares some eye-opening code snippets, but the game itself is closed source so it leaves something to be desired.
- single-thread CPU performance is pretty much 'good enough' now
- WebGL and WebGL2 too, but you have very different performance behaviour than a native GL driver (much higher call overhead for instance)
- pretty much all other HTML5 APIs: oh boy what a mess :/
Don't expect a 100 GB AAA Steam game to run on the web anytime soon, but mobile games will port over fine. It's better to define the web as your main platform, and design a new game from scratch around it's limitations.
So if you have a project which needs to do 3D rendering, audio, touch input etc... CPU performance is the least of your problems.
If they take advantage of OpenGL ES 3.0, 3.1 and 3.2 features not present in WebGL, it is going to be a bit hard.
Parsing isn't the only aspect of overall performance, though.
edit: * at least in Firefox, Chrome still has some... potential :)
That is only one of the advantages of WASM. The major advantage is that seen by CPU-bound code sections where WASM can be efficiently executed at "near" native speed.
Conversely, this performance advantage is not enjoyed by I/O-heavy operations which will not see any major improvement versus regular JS - this is roughly due to the browser having to apply sandboxing/security/protection (or by just forcing you to make JS calls to achieve this).
http://floooh.github.io/2017/06/09/webassembly-demystified.h...
Chrome: 40 FPS
60 FPS in Firefox 57.0, Chrome 62.0.3202.89, and Safari 11.0.1, on a 2017 iMac running High Sierra (10.13.1) with a 3.4 GHz Intel Core i5 and a Radeon Pro 570 4 GB.
I wonder what an iPhone would get, I'm led to believe their GPUs are pretty strong (to say the least).
EDIT - The above was in Chrome. In Firefox I actually get 23/24 fps at 4k (3.83M particles). At 1.8M in Firefox I get 48-50fps. Pretty good from Firefox.
Doesn't seem hardware limited, CPU and GPU utilisation doesn't go above 20% and I'm running other stuff like a decent sized VM and some other programmes.
I really don't know much about WASM. Would these numbers be deemed good? Is there more performance to squeezed out? I'm guessing there is as it's not fully utilising the hardware?
EDIT: Ah just noticed I'm only using 586k particles.