To explain the situation:
WebAssembly allows you to run programs in the web browser at almost the same speed as the desktop.
So if a program or language is slow on the desktop, it will be equally slow in WebAssembly. WebAssembly isn't magic, it cannot make your program faster than it is on the desktop.
So if you take Python and compile it to WebAssembly... it will be the same speed as Python running on the desktop.
Similarly, if you take Rust and compile it to WebAssembly, it will be the same speed as Rust on the desktop.
Since Rust running on the desktop is much faster than Python running on the desktop, Rust running on WebAssembly will also be much faster than Python running on WebAssembly.
That means any speed comparisons between languages on the desktop will (generally) translate over to WebAssembly as well.
So yes, your Rust program will run extremely fast on WebAssembly (faster than most languages), because Rust is quite fast on the desktop.
However, there is an additional factor with WebAssembly which doesn't exist on the desktop: file size.
With WebAssembly the browser must download the program before it runs it, so if the program is 50 megabytes then the user will be staring at a blank screen (or a loading screen) for a long time. So having a smaller file size means the user gets to start using the program sooner.
Rust generally produces smaller WebAssembly files (compared to other languages) because of the following reasons:
-
It doesn't have a garbage collector.
-
It doesn't have a runtime.
-
It has impressive dead code elimination.
-
It has a state of the art compiler (including LLVM) which gives many optimizations, some of which reduce file size.
-
It is designed for embedded programming which requires small file sizes. This means there are many things you can do to dramatically lower the file size.
A small "hello world" program in Rust compiled to WebAssembly is ~332 bytes. That's impossible in most other languages.
So Rust tends to be smaller in file size, faster in runtime performance, and smaller in memory usage compared to other languages (with the obvious exception of C/C++ which have the same advantages as Rust).
In addition, if there was a situation where a JIT was superior... you could just make a JIT for Rust. So you would have the benefits of AoT optimizations, but also the benefits of JIT.
(Sure, it's easier said than done to "just make a JIT", but it's certainly possible)