Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What engine does WebAssembly use?

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?

like image 221
karthikeayan Avatar asked Jun 10 '18 18:06

karthikeayan


People also ask

What is WebAssembly engine?

WebAssembly is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages with low-level memory models such as C++ and Rust with a compilation target so that they can run on the web.

Does WebAssembly run on V8?

For experimentation, V8 and Chrome can be configured to compile WebAssembly code only with Liftoff or only with TurboFan. It is even possible to experiment with lazy compilation, where functions only get compiled when they get called for the first time.

Is WebAssembly written in JavaScript?

WebAssembly is designed to complement and run alongside JavaScript — using the WebAssembly JavaScript APIs, you can load WebAssembly modules into a JavaScript app and share functionality between the two.

What is Chrome's V8 JavaScript engine?

Chrome V8 is a JavaScript engine, which means that it executes JavaScript code. Originally, JavaScript was written to be executed by web browsers. Chrome V8, or just V8, can execute JavaScript code either within or outside of a browser, which makes server-side scripting possible.


2 Answers

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.
like image 59
Yuhao Tiger Huang Avatar answered Sep 30 '22 04:09

Yuhao Tiger Huang


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

like image 24
ColinE Avatar answered Sep 30 '22 05:09

ColinE