Fireship · @fireship
Web Assembly (WASM) in 100 Seconds
Uploaded October 26, 2020 · Length 2:16
Summary
web assembly explained in 100 seconds, compilation target for web and native languages
- web assembly
- wasm
- compilation target
- low-level language
- assembly script
- typescript
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
web assembly write applications for the
- 0:02
web and languages other than javascript
- 0:04
imagine a world where you could build
- 0:06
software with c plus plus rust python go
- 0:09
or even cobalt then deliver that
- 0:10
software to the end user in a web
- 0:12
browser without any installation
- 0:14
and near native performance that world
- 0:15
became a reality in december 2019
- 0:18
when webassembly became an official w3c
- 0:20
standard
- 0:21
it includes a low-level language similar
- 0:22
to assembly that can be represented with
- 0:24
text
- 0:25
then converted to a binary format that
- 0:27
runs on all modern browsers
- 0:28
however you won't actually write this
- 0:30
code directly but rather use it as a
- 0:32
compilation target
- 0:33
for programs written in other languages
- 0:35
for example you might build a game with
- 0:37
unity and c-sharp
- 0:38
then compile it to webassembly where it
- 0:40
can be delivered in the browser
- 0:41
now it's important to note that it's not
- 0:43
intended to replace javascript
- 0:45
in fact the two work well together side
- 0:46
by side figma for example
- 0:48
uses react.js for its outer ui then on
- 0:51
the inside you have a high performance c
- 0:53
plus plus design tool that feels just as
- 0:55
fast as native software
- 0:56
as a developer there are many different
- 0:58
ways you can build a webassembly app
- 1:00
with many more under development one of
- 1:02
the most popular tools is mscriptin
- 1:04
which can convert a c
- 1:05
or c plus plus program to webassembly as
- 1:07
it did by bringing autocad to the web
- 1:09
which is a 30 year old codebase
- 1:11
no way one of the best ways to get
- 1:14
started is with assembly script which is
- 1:16
a language that looks like typescript
- 1:17
but compiles to webassembly we can
- 1:19
easily start a new assembly script
- 1:20
project
- 1:21
using node.js and npm then we'll write
- 1:23
our first webassembly module
- 1:25
in the index ts file unlike javascript a
- 1:28
dynamic interpreted language
- 1:29
webassembly is a static compiled
- 1:31
language with strict type guarantees
- 1:33
for example our code can't use the any
- 1:35
type when it comes to numbers
- 1:37
we need to specify a 32-bit integer or a
- 1:40
64-bit floating point
- 1:41
in addition we can't use dynamic objects
- 1:43
instead we use maps where we can
- 1:45
strongly type the key value pairs once
- 1:47
we're happy with our code we can then
- 1:48
compile it down to a binary which is a
- 1:50
file that ends in
- 1:51
wasm we can now run this binary in the
- 1:53
browser open an html page
- 1:56
and then use the webassembly api to
- 1:58
instantiate streaming
- 1:59
simply fetch the binary and when the


