3 ms·
> And it's not like you are going to get a huge performance benefit using Rust or C++ over assembly script. Or do they? Unlike Assembly Script, Rust and C++ us
by CryZe 4y ago
> And it's not like you are going to get a huge performance benefit using Rust or C++ over assembly script.
Or do they? Unlike Assembly Script, Rust and C++ use LLVM, which is a lot better at optimizing than binaryen.
- flohofwoe 4y agoWhat really counts for performance on modern CPUs are memory access patterns, if those are bad, LLVM's optimizer passes won't help much - especially since WASM itself is fairly highlevel too and requires further optimization when translated to machine code anyway. A more interesting question is instead: does AssemblyScript allow the same control over memory layout as C, C++ or Rust?
- CryZe 4y agoI don't think I agree. A debug build of Rust code is often like 40x slower or so than a release build. Those optimizations make a huge difference. Binaryen can only do a fraction of them, so I wouldn't expect AssemblyScript to get close to Rust and C++ (and the benchmarks show that too). > does AssemblyScript allow the same control over memory layout as C, C++ or Rust? There's no UB, so in a way AssemblyScript is almost more low level than those, as you have full control over the memory and instructions.
- flohofwoe 4y ago> A debug build of Rust code is often like 40x slower or so than a release build. Hmm ok, yeah. C++ with heavy stdlib (or generally: template) usage has the same problem (although in my experience it's more like 10..20x slower), but OTH C's debug and release build performance is usually much closer. I guess it's a side effect of generics that they heavily rely on the compiler optimization passes to turn the resulting 'generic mess' into something closer to what a human would write (e.g. remove all the redundant and dead code resulting from 'template resolution').
- pjmlp 4y agoAll of that boils down to quality of generated WebAssembly opcodes, nothing prevents an hypothetical AssemblyScript compiler to make use of better optimizations, or being based on LLVM and enjoy the same optimization passes on LLVM IR.
- maxgraey 4y agoThe main advantage of using Binaryen directly bypassing LLVM is firstly very fast codegen and optimization (Binaryen architecture perfectly utilizes multithreading as opposed to LLVM). In addition, clean and fast debug builds are not clogged with SSA and mSSA noise. That makes debug/release performance not more than 2-4x slower, unlike LLVM where this ratio is 20x-40x as already mentioned. The Binaryen optimizer is improving all the time. It is already better in many places than the same Go's codegen
- zarzavat 4y agoThey probably meant compiling Rust to WASM, not comparing WASM vs native code which is a choice you would make separately to the programming language.
- andai 4y agoLLVM can compile to webassembly.