suelopoder / rust-wasm-test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What

This app is a simple test for Rust on the web via WASM. I test a simple sort of a big array in plain JS and in a compiled rust lib. Then I tried both again but loaded from a web worker.

Chrome timing console output Chrome performance recording

Performance results

As expected Rust beats JS sorting a JS array for big arrays. It's worth noting that both block the main thread. The workaround is to sort within a web worker, with similar timings but not blocking. Results

Demo

How

Run wasm-pack build --target no-modules to build the JS glue code. Then open index.html in a browser.

Unit test

To test rust code run: wasm-pack test --node

Why

Test rust and JS interactions and wrap my head around when it would be a good idea to use it.

Resources

Next steps

I wonder if we could return a promise in Rust that will execute in background. This shouldn't improve performance though.

About


Languages

Language:HTML 67.9%Language:JavaScript 19.6%Language:Rust 12.5%