Majic-Jungle / sapiens-mod-creation

Official tools and examples for mod creation in the game Sapiens
MIT License
54 stars 12 forks source link

[Idea] Wasm mods #1

Closed bddap closed 4 years ago

bddap commented 4 years ago

Hey dave. Have you considered embedding a webassembly runtime and compiling mods to wasm?

  1. It solves security concerns by sandboxing.
  2. wasm is great for server-provided mods because they don't need to be rebuilt for every supported client.
  3. wasm runtimes are getting really fast, wasmer with llvm backend clocks in around 1.5 times native speed on benchmarks.
mjdave commented 4 years ago

Thanks for the suggestion, but I think I'm relatively happy with the solution I have.

I already have Lua/LuaJIT that does a great job for supporting most of the requirements of mod development. The issue I faced was performance when doing things that required a lot of updating of little bits of data, in particular terrain generation and the particle system. The issue was that the interface that I had between Lua and C++ was slowing things down.

I could probably have solved this by actually moving more of the data and code to LuaJIT/FFI, which would have reduced a lot of the performance bottlenecks, but I decided instead to make it as fast and simple as I reasonably could, by implementing the C plugin system for those things that just have to be as fast as possible.

So I don't see how wasm fits in this scenario, and I'm already far too deep. It would be quite a bit of work to now investigate, learn, and implement a new language/system, and really doesn't seem like a good idea for the project at this point.

I'll keep it in mind for future projects though.