I have been curious about web assembly for a long time. I knew of some resources that could help me learn it. One of those resources was the wasm-bindgen book. Eventually I put in the time to learn how to make a web assembly application using Rust, and I wanted to see what were the performance benefits.

There were several different obstacles that I overcame. I had to learn some web assembly terminology. As I was learning web assembly terminology, I arranged my project in a specific format to resemble JS work, and plus it just looks cleaner. Part of that formatting was making an actual crate, because I thought it would pull out some logic.

In the end, the project turned out well! The crate is published and it’s definitely not extensive by any means. Maybe it’ll get used more and people will start making web apps with Web Assembly? That would be something. Or I’ll decide to build more web applications myself and build out the crate.

Stats from Project

I made two different applications in the same project. One application ran with Rust/WebAssembly and the other ran with JavaScript. Both applications calculate all the prime numbers between 1 and a given number. Then all the calculated prime numbers are displayed on the web page.

Here are the stats! As can be seen by the stats, WebAssembly brings in the efficiency. JS just starts to loose right around 10,000, and seriously sweats with over a million. Web Assembly handles over a million just fine.

Rust web application

prime number calc maxtime duration
10~ 0.5ms
100~ 0.5ms
1,000~ 0.5ms
10,000~ 0.8ms
100,0003-5 ms
1,000,00015 - 30 ms
10,000,000~ 130 ms

JS web application

prime number calc maxtime duration
10~ 0.5ms
100~ 0.5ms
1,000~ 0.5ms
10,0001-3 ms
100,00010-15 ms
1,000,000122-126 ms
10,000,000~ 2450 ms

Conclusion

Now I’m still a fan of JavaScript. For relatively smaller tasks, JavaScript is just fine to use. But for significantly bigger tasks, WebAsssembly needs to be considered. I think that using Rust for WebAssembly will be important in my career sometime. I just don’t know how. I hope it will be! This project taught me how to use Web Assembly in the browser. Thanks to the guys that made wasm-bindgen and other crates to make this possible!