最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What engine does WebAssembly use? - Stack Overflow

programmeradmin3浏览0评论

In Chrome, JavaScript runs on the V8 Engine, but what is the engine that runs WebAssembly code?

How is the browser suddenly able to give improved performance with WebAssembly? Is this WebAssembly engine always available in browser, or has it been added to browsers recently?

In Chrome, JavaScript runs on the V8 Engine, but what is the engine that runs WebAssembly code?

How is the browser suddenly able to give improved performance with WebAssembly? Is this WebAssembly engine always available in browser, or has it been added to browsers recently?

Share Improve this question edited Dec 12, 2018 at 20:28 Jack 2,2852 gold badges25 silver badges38 bronze badges asked Jun 10, 2018 at 18:59 karthikeayankarthikeayan 5,0009 gold badges41 silver badges89 bronze badges 3
  • does it mean we have a compiler which compiles C/C++/Rust programs into JavaScript? if yes, why can't we achieve same performance with native JavaScript? – karthikeayan Commented Jun 10, 2018 at 19:04
  • 1 @SLaks You're confusing WebAssembly with asm.js – Bergi Commented Jun 10, 2018 at 19:11
  • "Does this WebAssembly engine always available in browser?" - no, it's being added to recent browser version only. However you could use a JS library that loads the wasm files and interprets the bytecode (at a much slower rate than the native implementation) as a polyfill so that it works in older browsers as well – Bergi Commented Jun 10, 2018 at 19:14
Add a comment  | 

3 Answers 3

Reset to default 11

WebAssembly is a new web standard instruction set that is executed by the browser. Within Chrome WebAssembly runs within V8 https://v8project.blogspot.com/2016/03/experimental-support-for-webassembly.html?m=1

WebAssembly is only supported by all major browser (Chrome, Firefox, Safari, Edge) since Nov/2017, meaning WebAssembly is not supported by older version of browsers. (blog post from mozilla)

To understand why WebAssembly is faster then Javascript there is a excellent series by Lin Clark (link).

The conclusion from the article is quote

WebAssembly is faster than JavaScript in many cases because:

  • fetching WebAssembly takes less time because it is more compact than JavaScript, even when compressed.
  • decoding WebAssembly takes less time than parsing JavaScript.
  • compiling and optimizing takes less time because WebAssembly is closer to machine code than JavaScript and already has gone through optimization on the server side.
  • reoptimizing doesn’t need to happen because WebAssembly has types and other information built in, so the JS engine doesn’t need to speculate when it optimizes the way it does with JavaScript.
  • executing often takes less time because there are fewer compiler tricks and gotchas that the developer needs to know to write consistently performant code, plus WebAssembly’s set of instructions are more ideal for machines.
  • garbage collection is not required since the memory is managed manually.

There are many runtimes for WebAssembly such as the browser (V8, SpyderMonkey, JavaScriptCore). Also, there are runtimes which implement the WASI such as:

  • Wasmtime which uses Cranelift and in turn, LLVM
  • WAVM which uses LLVM
  • Wasm3 which is an interpreter in wasm
  • GraalVM WASM which uses a JVM implementation and then LLVM
  • Lunatic which uses WasmTime and native bindings
  • and more

WebAssembly can run on many runtimes and so in turn, it can operate on many machines and vms

发布评论

评论列表(0)

  1. 暂无评论