it would be relatively easy to rewrite scratch-vm in Rust and compile it to WebAssembly and run Scratch projects in the browser at potentially inane speeds
https://github.com/HyperQuark/hyperquark 🗣️
though if you cap it at 30fps it’ll do nothing but make them run at a more consistent framerate, which is nice
if this was something the devs would actually do though, i fear people would just make unoptimized projects because there’s no reason for it, but this is a silly experiment of mine so there is no cause for concern
maybe i could get it added to turbowarp as an optional setting? (if i complete it, that is)
i would be surprised if a VM written in WASM would give amazing speeds because:
WASM-JS interop, of which a lot would be required (for interfacing with blockly, rendering, audio and network stuff), is pretty expensive
most of the speed gains that WASM offers are (from my experience) having static and lower-level types. this isn't really something you can take advantage of much in an interpreter
however there are probably components of the vm that could benefit from wasm-ification (technical term i know) such as scratch-render - i think tw might already have some wasm going on there (or at least there was a pr to do something in wasm).
having said that i'd love to see a vm written in rust because that's just cool
oh interop is slow? had no idea
having said this, I've done some more reading and it sounds like the overhrad of actually calling host-provided functions from wasm these days is fairly negligible (it didn't use to be!). however i'm still a bit skeptical about it from personal experience - i suspect that's just due to some things being difficult for the js engine to optimise when they're separated by world boundaries. but yes back when wasm was first getting started, js interop was orders of magnitude slower than regular function calls
“overhrad” lol
what about wasm-provided functtions from host?
:sob:
i think js→wasm calls should be pretty quick these days (in firefox there're faster than normal non-inlined js→js calls i think, if you pass the same types into them every time)