Hacker News new | ask | show | jobs
by hajile 1430 days ago
The rust code is 3x as long and a lot more complex too.

In theory, static typing would correct the biggest performance issues in JS (use monomorphic functions, don't mutate objects, and limit arrays of just one primitive/object type).

In practice, TypeScript allows and encourages you to create types that are horrendous for performance.

I'd love to see a comparison using AssemblyScript (basically stricter TS for WASM). I'd bet it's nearly the same speed as Rust while still being a third of the size.

2 comments

The Rust version is longer mostly due to boilerplate for WASM<>JS interface, and awful vertically-exploded formatting (probably caused by rustfmt's dumb heuristics).

but the core loop in Rust is pretty straightforward. It could have been shortened and optimized further.

Also keep in mind that the larger the project, the harder it gets to keep JS in the performance sweet spot without tipping over any JIT heuristic, using GC, or accidentally causing a perf cliff, while the Rust has pretty stable and deterministic optimizations and keeps its memory management control at any scale.

https://blog.suborbital.dev/assemblyscript-vs-rust-for-your-...

This is a pretty good rundown of expected comparisons, but I doubt there will be any surprises here.