Live data from Hacker News

Comparing Rust and JavaScript

chaotic.netlify.app

91–97 of 97 posts

Re: Comparing Rust and JavaScript

#91
post #61

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

From the user-experience perspective, it matters that it is Rust. Unless you directly write WASM code, which is rarely (ever) the case. Rust is a language that compiles to WASM. Sure, there are other options to compile to WASM, but they differ by interface (programming language, library, tooling) and (likely to a lesser degree) - performance.

[deleted]

Re: Comparing Rust and JavaScript

#93

Earlier quoted context omitted.

Has anyone compiled v8 to WASM so we can finally run JS in the browser? ;)

v8 is a JIT engine, WASM would not support it. JavaScriptCore has been compiled to WASM though: https://mbbill.github.io/JSC.js/ People usually ask why, the answer is usually for fun or for sandboxed plugins.

I imagine that, if one were feeling extremely masochistic, one could generate WASM, JIT-style, and load it as needed. The result may not perform well.

Re: Comparing Rust and JavaScript

#94

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

The language whose compiler generated the code is relevant, as it often constrains what the generated code look like in broad terms.

Re: Comparing Rust and JavaScript

#95

Earlier quoted context omitted.

Has anyone compiled v8 to WASM so we can finally run JS in the browser? ;)

v8 is a JIT engine, WASM would not support it. JavaScriptCore has been compiled to WASM though: https://mbbill.github.io/JSC.js/ People usually ask why, the answer is usually for fun or for sandboxed plugins.

I assumed the JIT would emit WASM.

Re: Comparing Rust and JavaScript

#96
post #40

Earlier quoted context omitted.

Last I checked, destructuring created 4-5x as many bytecode instructions and a potential GC pause. I'd think this could be detected and optimized easily enough, but I guess there are bigger problems for the JIT devs to solve. A quick profiling seemed to indicate that just a bit less than 10% of the JS time is being spent on the DOM rather than the calculations at hand. I wonder how much of that could be reclaimed sim…

I actually thought Math.max was faster in modern Chrome than a ternary.

You can try for yourself (this uses an if..else, but they compile to the same thing)

https://www.measurethat.net/Benchmarks/Show/6528/0/mathmin-v...

Post reply on HN