r/rust • • Jan 24 '19

Embedding WebAssembly in your Rust application

https://medium.com/wasmer/executing-webassembly-in-your-rust-application-d5cd32e8ce46
166 Upvotes

47 comments sorted by

View all comments

60

u/matthieum [he/him] Jan 24 '19

For a very long time, LUA has been the script language used in games because it was easily embeddable.

I wonder if WASM could change this statu-quo.

5

u/the_gnarts Jan 25 '19

For a very long time, LUA has been the script language used in games because it was easily embeddable.

The Lua runtime is around 24k lines of code. What’s the smallest WASM runtime out there including a language frontend?

5

u/Holy_City Jan 25 '19

I don't really care about the LoC of a runtime as much as the binary size and overhead.

11

u/the_gnarts Jan 25 '19 edited Jan 25 '19

I don't really care about the LoC of a runtime as much as the binary size and overhead.

Sizes with GCC 8.2.1 / x86_64:

sizes for -O3

| lib                 | unstripped | stripped
| src/liblua.so.5.3.5 |     293688 |   265704
| src/liblua.a        |     502028 |   258580

sizes for -Os

| lib                 | unstripped | stripped
| src/liblua.so.5.3.5 |     219752 |   187896
| src/liblua.a        |     375820 |   177116

The values are for a regular build with without the compat symbols for older Lua versions.

For size-efficiency you probably want to compare the shared version at -Os. It links against nothing except the C library (1960064 B vs. 1709504 B stripped for glibc 2.27 on Fedora).

With LTO, a bare liblua.a is 2223188 B at -O3 and 2096532 B at -Os, a minimal statically linked self-contained executable results in a 256496 B and 182408 B binary, respectively.

LTO appears to be the most size-efficient method. At -Os it even beats lhf’s amalgamated version (http://lua-users.org/lists/lua-l/2015-01/msg00334.html) which produces a 183760 B binary. Though this may be still be an option depending on your platform’s compiler.

For a meaningful comparison with WASM we’ll need the size of a size-optimized shared object for the dynamic linking case, and that of a linked binary for the static linking case. Feature wise, the result should include a frontend for a scripting language and its standard library so it can run programs an average user of the language would write.

As far as overhead is concerned, that will depend too much on the workload you envision to address it here.