WebAssembly

@ethebault

Demo

Il était une fois

le web

1995

Avenir du web (1995)

  • Abandonné par les navigateurs
  • Déprécié en Java 9

DHTML

Fin 90

Optimisation

ASM JS

Ajout d'un ensemble d'instruction

  • Typage des variable
  • Gestion manuelle de la mémoire

Web Assembly

enfin...

Annoncé en 2015

Demo en 2016

Supporte par les navigateurs

depuis mi 2017

Cas d'utilisation

  • Edition d'image/vidéo
  • Réalité augmenté
  • Machine learning
  • Server web local
  • Application hybride native pour mobile
  • ...

MVP

  • Iso-fonctionnel avec ASM
  • Module WASM
    • Instructions "assembleurs"
    • Format binaire
    • Format texte (assembleur, debuggeur)
  • Implementations
    • navigateurs
    • mobile
    • IOT device
    • serveur

Runtime

WASM

0000000: 0061 736d                                 ; WASM_BINARY_MAGIC
0000004: 0100 0000                                 ; WASM_BINARY_VERSION
; section "Type" (1)
0000008: 01                                        ; section code
0000009: 00                                        ; section size (guess)
000000a: 02                                        ; num types
; type 0
000000b: 60                                        ; func
000000c: 01                                        ; num params
000000d: 7f                                        ; i32
000000e: 00                                        ; num results
; type 1
000000f: 60                                        ; func
0000010: 00                                        ; num params
0000011: 00                                        ; num results
0000009: 08                                        ; FIXUP section size
; section "Import" (2)
0000012: 02                                        ; section code
0000013: 00                                        ; section size (guess)
0000014: 01                                        ; num imports
; import header 0
0000015: 07                                        ; string length
0000016: 696d 706f 7274 73                        imports  ; import module name
000001d: 0d                                        ; string length
000001e: 696d 706f 7274 6564 5f66 756e 63         imported_func  ; import field name
000002b: 00                                        ; import kind
000002c: 00                                        ; import signature index
0000013: 19                                        ; FIXUP section size
; section "Function" (3)
000002d: 03                                        ; section code
000002e: 00                                        ; section size (guess)
000002f: 01                                        ; num functions
0000030: 01                                        ; function 0 signature index
000002e: 02                                        ; FIXUP section size
; section "Export" (7)
0000031: 07                                        ; section code
0000032: 00                                        ; section size (guess)
0000033: 01                                        ; num exports
0000034: 0d                                        ; string length
0000035: 6578 706f 7274 6564 5f66 756e 63         exported_func  ; export name
0000042: 00                                        ; export kind
0000043: 01                                        ; export func index
0000032: 11                                        ; FIXUP section size
; section "Code" (10)
0000044: 0a                                        ; section code
0000045: 00                                        ; section size (guess)
0000046: 01                                        ; num functions
; function body 0
0000047: 00                                        ; func body size (guess)
0000048: 00                                        ; local decl count
0000049: 41                                        ; i32.const
000004a: 2a                                        ; i32 literal
000004b: 10                                        ; call
000004c: 00                                        ; function index
000004d: 0b                                        ; end
0000047: 06                                        ; FIXUP func body size
0000045: 08                                        ; FIXUP section size
wast2wasm module.wast -v

Format binaire

  • Taille
  • Temps de chargement
  • Cible la vitesse d’exécution d'une app native
  • "Sécurité"

WAST

  (func (;18;) (type 5) (param i32 i32)
    get_global 14
    i32.const 0
    i32.eq
    if  ;; label = @1
      get_local 0
      set_global 14
      get_local 1
      set_global 15
    end)
  (func (;19;) (type 3) (param i32)
    get_local 0
    set_global 25)
  (func (;20;) (type 2) (result i32)
    get_global 25
    return)

WABT

WebAssembly Build Tool

wast2wasm module.wast -o module.wasm

WAST

WASM

Demo

Inutilisable !!!

Utilisation d'un langage de

"haut niveau"

Langages compatibles

C#:Blazor

LLVM

Source file

LLVM Compiler

*.s

LLVM IR files

WebAssembly

Compiler

*.wasm

 

Pas simple

git clone https://github.com/juj/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest

source ./emsdk_env.sh
emcc hello.c -s WASM=1 -s NO_EXIT_RUNTIME=1  -g4 -o index.js

emrun --no_browser --port 8080 .

Demo

Lecteur audio FLAC

  • Décodeur flac
  • API Audio

LibFlac

  • autogen
  • configure
  • make

=> Réussir à le compiler normalement !!!

API Multimedia

API Fichier

A suivre

  • Threads
  • Exception handling
  • Garbage collection
  • ECMAScript module integration
  • Autres langages/compilateurs

Merci

Web Asembly (BrestJS)

By erwann thebault

Web Asembly (BrestJS)

  • 1,230