Fireship · @fireship

Web Assembly (WASM) in 100 Seconds

Uploaded October 26, 2020 · Length 2:16

Web Assembly (WASM) in 100 Seconds

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.

  1. 0:00

    web assembly write applications for the

  2. 0:02

    web and languages other than javascript

  3. 0:04

    imagine a world where you could build

  4. 0:06

    software with c plus plus rust python go

  5. 0:09

    or even cobalt then deliver that

  6. 0:10

    software to the end user in a web

  7. 0:12

    browser without any installation

  8. 0:14

    and near native performance that world

  9. 0:15

    became a reality in december 2019

  10. 0:18

    when webassembly became an official w3c

  11. 0:20

    standard

  12. 0:21

    it includes a low-level language similar

  13. 0:22

    to assembly that can be represented with

  14. 0:24

    text

  15. 0:25

    then converted to a binary format that

  16. 0:27

    runs on all modern browsers

  17. 0:28

    however you won't actually write this

  18. 0:30

    code directly but rather use it as a

  19. 0:32

    compilation target

  20. 0:33

    for programs written in other languages

  21. 0:35

    for example you might build a game with

  22. 0:37

    unity and c-sharp

  23. 0:38

    then compile it to webassembly where it

  24. 0:40

    can be delivered in the browser

  25. 0:41

    now it's important to note that it's not

  26. 0:43

    intended to replace javascript

  27. 0:45

    in fact the two work well together side

  28. 0:46

    by side figma for example

  29. 0:48

    uses react.js for its outer ui then on

  30. 0:51

    the inside you have a high performance c

  31. 0:53

    plus plus design tool that feels just as

  32. 0:55

    fast as native software

  33. 0:56

    as a developer there are many different

  34. 0:58

    ways you can build a webassembly app

  35. 1:00

    with many more under development one of

  36. 1:02

    the most popular tools is mscriptin

  37. 1:04

    which can convert a c

  38. 1:05

    or c plus plus program to webassembly as

  39. 1:07

    it did by bringing autocad to the web

  40. 1:09

    which is a 30 year old codebase

  41. 1:11

    no way one of the best ways to get

  42. 1:14

    started is with assembly script which is

  43. 1:16

    a language that looks like typescript

  44. 1:17

    but compiles to webassembly we can

  45. 1:19

    easily start a new assembly script

  46. 1:20

    project

  47. 1:21

    using node.js and npm then we'll write

  48. 1:23

    our first webassembly module

  49. 1:25

    in the index ts file unlike javascript a

  50. 1:28

    dynamic interpreted language

  51. 1:29

    webassembly is a static compiled

  52. 1:31

    language with strict type guarantees

  53. 1:33

    for example our code can't use the any

  54. 1:35

    type when it comes to numbers

  55. 1:37

    we need to specify a 32-bit integer or a

  56. 1:40

    64-bit floating point

  57. 1:41

    in addition we can't use dynamic objects

  58. 1:43

    instead we use maps where we can

  59. 1:45

    strongly type the key value pairs once

  60. 1:47

    we're happy with our code we can then

  61. 1:48

    compile it down to a binary which is a

  62. 1:50

    file that ends in

  63. 1:51

    wasm we can now run this binary in the

  64. 1:53

    browser open an html page

  65. 1:56

    and then use the webassembly api to

  66. 1:58

    instantiate streaming

  67. 1:59

    simply fetch the binary and when the