alexdovzhanyn / AlchemyVM

WebAssembly Virtual Machine Built In Elixir
MIT License
188 stars 5 forks source link

Parallel decoding #20

Closed alexdovzhanyn closed 5 years ago

alexdovzhanyn commented 5 years ago

Fixes #13 by allowing parallelism to be specified when loading Wasm into the VM. When calling load_file/3 or load/3, the third parameter (defaults to true) specifies whether or not to decode the module's sections in parallel.

Parallelism offers performance improvements in decoding speed on all but tiny file sizes. Here are some benchmarks:

For a ~8 KB file:

Name               ips        average  deviation         median         99th %
parallel          6.88      145.43 ms     ±1.29%      144.62 ms      150.27 ms
linear            5.53      180.89 ms     ±2.51%      179.94 ms      191.94 ms

Comparison:
parallel          6.88
linear            5.53 - 1.24x slower

For an 80 byte file:

Name               ips        average  deviation         median         99th %
linear         12.10 K       82.66 μs    ±64.40%          77 μs         181 μs
parallel        6.86 K      145.85 μs    ±22.02%         139 μs      259.54 μs

Comparison:
linear         12.10 K
parallel        6.86 K - 1.76x slower