Live data from Hacker News

Comparing Rust and JavaScript

chaotic.netlify.app

11–20 of 97 posts

Re: Comparing Rust and JavaScript

#11
The difference in performance is about 3x and it looks like an pretty ideal case for wasm. Seems to match observations from Zaplip portmortem:

> Rust is faster than JS in some cases, but those cases are rarer than we expected, and the performance gain is on the order of 2x some of the time, not 10x most of the time.

https://zaplib.com/docs/blog_post_mortem.html

Re: Comparing Rust and JavaScript

#12
post #10
post #7

I get that the intended meaning is "JS sux", but I can't help being impressed with how performant engines are. The "pixels per ms" count ratio is less than 3:1 on my machine, in what I imagine is a CPU-heavy task.

On my phone it's closer to 6:1. 500 jumps to 3000 with WASM

What kind of phone? My iPhone 7 (pretty old) is around 2800 vs 6000 with WASM.

Re: Comparing Rust and JavaScript

#15
On my iPhone: 2.8K vs 6K (WASM)

On my Linux laptop, Firefox: 1.7K vs 3K

On my Linux laptop, Brave: 1.5K vs 6K

It does seem to vary quite a bit based on the pattern being drawn, though. These ratios seem to roughly hold, but there's wide variance.

Re: Comparing Rust and JavaScript

#16
The innermost rendering loop in the JS seems to create and destruct an array instance for every single pixel iteration (see https://github.com/dmaynard/chaos-screen-saver/blob/master/s...). I guess that this could be potentially optimized away by the JIT, but it will make things slower or at least less predictable.

Re: Comparing Rust and JavaScript

#17

More of a comparison between WebAssembly and JavaScript, really. That the WebAssembly was compiled from Rust is not especially meaningful here.

I wouldn't say the source language is not meaningful. If you wrote an ahead-of-time JavaScript-to-WebAssembly compiler and benchmarked the WASM generated by that, it would probably be a lot slower than the WASM generated by the Rust compiler, no?

Re: Comparing Rust and JavaScript

#18

I'm curious why a lot of people get a 3x improvement. I get about 6.5-7x speed up, which suspiciously lines up with a 60hz vs 144hz framerate...

This seems related to the screen size, also.

On my 4k screen (which I run at 100% scaling) on Firefox on Linux I get around 2700 on ES and 7500 on WASM.

But if I reduce the window size to half the screen, I get 3000 for ES and 10000 for WASM.

Re: Comparing Rust and JavaScript

#19

More of a comparison between WebAssembly and JavaScript, really. That the WebAssembly was compiled from Rust is not especially meaningful here.

True, but if you where in a front-end project doing JS with some WASM parts that happened to use Rust for the WASM, you'd probably not ask yourself "JS or WASM?", you'd ask yourself "JS or Rust?" when deciding where to put some logic.

And I'm not sure if we can assume that all languages that offer compilation to WASM would be roughly "rust fast": I wouldn't be surprised if we already had some examples that aren't really good matches for that tight inner loop case you might want to wasmify. Perhaps there are already some that just want to get the "runs in browser" checkbox ticked?

Re: Comparing Rust and JavaScript

#20

More of a comparison between WebAssembly and JavaScript, really. That the WebAssembly was compiled from Rust is not especially meaningful here.

The fact that it was written in Rust (or any other non-VM lang) is meaningful because programs written in a Language that needs a VM (All the GC'd languages for example) need the vm to be shipped as well. Thus, making the WASM-program larger and slower.
Post reply on HN