-3

I'm implementing a Mandelbrot Set visualization using Rust with WebAssmbly, where my goal is to make it using multi-threading.

I've implemented the Mandelbrot Set both in Javascript (using Typescript) and in Rust single-threaded so far. I've made some benchmarks and the Rust implementation is about x17 time slower, and I'm completely lost here, I don't know why I'm getting this bad performance.

Here is the repo, at master the implementation that uses Rust, and in js-implementation the one with Rust.

https://github.com/DanielRamosAcosta/mandlerbot-set-webassembly

Thanks in advance.

10
  • 1
    The JavaScript engines were optimized since more than 10 Years, the WASM engines are just a year old. Nov 30, 2018 at 19:31
  • 2
    @JonasWilms The whole point of Wasm is that it is meant to run a lot faster than JavaScript. This is from the first few sentences of the Wikipedia article: "[Wasm] is meant to enable executing code nearly as quickly as running native machine code. It was envisioned to complement JavaScript to speed up performance-critical parts of web applications and later on to enable web development in languages other than JavaScript." Nov 30, 2018 at 19:35
  • 3
    @daniel-ramos can you provide some instructions of how to build the source code? I'm getting an error about trying to build it and that makes it difficult to try to reproduce the measurements! Otherwise one problem I can see so far is that you're not using cargo build --release (note how you're running wasm-bindgen over the debug folder). The Rust and WebAssembly book has a great section on time profiling if you're interested as well! Nov 30, 2018 at 20:15
  • 2
    @JonasWilms Basically the main point of Wasm is that it actually does run faster in practice. Much of it runs at near-native speed, and even the best optimised JavaScript JIT won't be able to compete with it. I recommend reading this nice article by Lin Clark as an introduction. Nov 30, 2018 at 22:40
  • 2
    Possible duplicate of Why is my Rust program slower than the equivalent Java program?
    – hellow
    Dec 3, 2018 at 11:39

1 Answer 1

3

Remember to use the --release flag when building.

Not the answer you're looking for? Browse other questions tagged or ask your own question.