WebAssembly: what and how







This article is based on my presentation at the ITSubbotnik conference, held on November 2, 2019 in Moscow.







In general, I am a backend programmer, but I was interested in this technology, it allows me to use my backend knowledge at the front.







Problem



Let's start with the problem that is being solved by this (relatively new) technology. This problem is to quickly execute code in a browser . Fast - it means “faster than JavaScript”, ideally as fast as our current processor allows.

In addition, historically, important additional requirements gradually arose around this problem:









History before Wasm



We saw many options for executing code in a browser. We can say that there are winners and losers in this field.













Winners: This is definitely JavaScript; the V8 engine that made JS so fast; as well as HTML5.







Losers: ActiveX - if you remember, this technology allowed you to do anything with the machine in general, i.e. security was very bad; Flash - now we are witnessing the era of the decline of Flash, although ActionScript works inside it, in fact, the same JavaScript; Silverlight - he must have appeared too late to occupy a serious niche.

As a result, all plugins lost, including due to security problems.







There were other attempts to solve the problem, already in the browser:









asm.js



asm.js is another interesting initiative, already from the Mozilla Foundation, which brings us close to the topic of WebAssembly. It appeared in 2010, and in 2013 it became publicly available.







asm.js is a subset of JavaScript, you can compile code from C and C ++ using the Emscripten compiler.







Since this is also JavaScript, this code will be executed in any browser. In addition, the main modern browsers have long been able to quickly recognize asm.js and efficiently compile it into the processor’s native code. Compared to the native code obtained directly from C / C ++, the code obtained from asm.js is slower by only 1.5-2 times (50-67%).













C/C++, asm.js. -, 'use asm'



, , , asm.js. |0



, . , 32- . JavaScript. , , .. .







, asm.js , JS, .







WebAssembly









WebAssembly ( Wasm) — , , , .







Wasm , - Java , .







- , web assembly ( « ») , ( ) ( ).







WebAssembly — . Evolving Wasm into a proper misnomer: Andreas Rossberg.













, — -, , . , «» — . «», Google, Mozilla, Microsoft Apple.







, Wasm .













« », , . : , . — . .













: , 64 . , , , , , . , , 64 .







( ), . 32-, 4 .







WebAssembly JavaScript, , .













WebAssembly. Wasm JavaScript. , JS Wasm «», .







, Wasm JS. , JS-.







WebAssembly



WebAssembly, WasmFiddle WebAssembly Studio — , Wasm .













C/C++ ( , ), JS Wasm, Wasm- fib()



. Build, Wasm (.wasm ), (.wat ).







— , (AST). Lisp. , , — . Wasm .







2017 : Production Ready



2017 WebAssembly « ». Wasm , Wasm . , WebAssembly «» MVP — Minimum Viable Product, 1.0, .









2017 WebAssembly:













— IE11, , , . , polyfill — Wasm asm.js; , , , , .







, ~88% Wasm.















, Wasm, . Wasm, . . appcypher/awesome-wasm-langs.









, LLVM Wasm . , , Wasm.









, — « Wasm?»







WebAssembly :









:











Wasm «» , ?







JavaScript, , Wasm , JS/Wasm, , . .







, JS Wasm , . JS , Wasm «» .







, Wasm . , Wasm . — JS <-> Wasm. . , .













2019 «Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code». WebAssembly Linux, , SPEC Wasm asm.js .







:









, Wasm «»:









, , . , Wasm .







Wasm , , : , SIMD-, threads.







?



WebAssembly?







-, , Wasm, . (), « » .







, :









-, , , , .. Wasm , « » , .







, , Chrome, WebAssembly.

Firefox .







WebAssembly



, Wasm , . , .







Wasm :









Wasm , «», , — , / .. WebAssembly System Interface (WASI) — - API, POSIX. . WebAssembly/WASI wasi.dev.













Wasm Package Manager (WAPM) — wapm.io. .wasm- . Wasm- - . «WASI», — .









, WebAssembly , «production ready».

Wasm , JavaScript, , .

Wasm .







, WebAssembly « » — , .











Awesome :









:










All Articles