Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

WebAssembly. Neither Web Nor Assembly, All Revolutionary

127 vues

Publié le

Video and slides synchronized, mp3 and slide download available at URL https://bit.ly/2tWqrMm.

Jay Phelps talks about WebAssembly, a bytecode designed and maintained by some of the major players in tech: Google, Microsoft, Apple, Mozilla, Intel, LG, and many others. He talks about what WebAssembly is and what it isn’t. Filmed at qconsf.com.

Jay Phelps is the Chief Software Architect and Co-founder at This Dot, where they provide support, training, mentoring, and software design. Previously, he worked as a Senior Software Engineer at Netflix.

Publié dans : Technologie
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

WebAssembly. Neither Web Nor Assembly, All Revolutionary

  1. 1. WebAssemblyneither Web nor Assembly, but Revolutionary Jay Phelps | @_jayphelps
  2. 2. InfoQ.com: News & Community Site • Over 1,000,000 software developers, architects and CTOs read the site world- wide every month • 250,000 senior developers subscribe to our weekly newsletter • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • 2 dedicated podcast channels: The InfoQ Podcast, with a focus on Architecture and The Engineering Culture Podcast, with a focus on building • 96 deep dives on innovative topics packed as downloadable emags and minibooks • Over 40 new content items per week Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ webassembly-intro
  3. 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon San Francisco www.qconsf.com
  4. 4. Jay Phelps | @_jayphelps The WebAssembly revolution has begun
  5. 5. Chief Software Architect | previously Jay Phelps @_jayphelps
  6. 6. Support, Dev Rel, Staff Augmentation, Mentorship, and more www.thisdot.co
  7. 7. Jay Phelps | @_jayphelps So...what is WebAssembly? aka Wasm
  8. 8. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  9. 9. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  10. 10. Jay Phelps | @_jayphelps Fast to load and execute
  11. 11. Jay Phelps | @_jayphelps Streaming compilation compiled to machine code faster than it downloads
  12. 12. (func $0 (type 0) i32.const 0 i32.load ) (func $1 (type 0) i32.const 0 i32.load ) (func $2 (type 0) i32.const 0 i32.load ) (func $3 (type 0) i32.const 0 i32.load ) .wasm
  13. 13. (func $0 (type 0) i32.const 0 i32.load ) (func $1 (type 0) i32.const 0 i32.load ) (func $2 (type 0) i32.const 0 i32.load ) (func $3 (type 0) i32.const 0 i32.load ) .wasm machine code
  14. 14. (func $0 (type 0) i32.const 0 i32.load ) (func $1 (type 0) i32.const 0 i32.load ) (func $2 (type 0) i32.const 0 i32.load ) (func $3 (type 0) i32.const 0 i32.load ) .wasm machine code
  15. 15. wasm-function[0]: sub rsp, 8 mov eax, dword ptr [r15] nop add rsp, 8 wasm-function[1]: sub rsp, 8 mov eax, dword ptr [r15] nop add rsp, 8 wasm-function[2]: sub rsp, 8 mov eax, dword ptr [r15] nop add rsp, 8 wasm-function[3]: sub rsp, 8 mov eax, dword ptr [r15] nop add rsp, 8 .wasm machine code
  16. 16. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Websafe
  17. 17. Jay Phelps | @_jayphelps Sandboxed and designed with security in mind Control-flow integrity checks, stack protection, dynamic dispatch table separate from linear memory
  18. 18. Jay Phelps | @_jayphelps However, does not prevent all classes of exploits Code reuse, side channel, race conditions, etc
  19. 19. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Weblow-level bytecode
  20. 20. Jay Phelps | @_jayphelps WebAssembly is a portable, binary instruction set for a virtual machine
  21. 21. Jay Phelps | @_jayphelps 0x6a01101010 (the i32.add instruction)
  22. 22. Jay Phelps | @_jayphelps Intended (mostly) as a compilation target
  23. 23. int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } }
  24. 24. int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } } 00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B
  25. 25. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  26. 26. Jay Phelps | @_jayphelps How did we get here?
  27. 27. Jay Phelps | @_jayphelps Primary goals: languages other than JavaScript and great—ideally improved—performance
  28. 28. Jay Phelps | @_jayphelps Java Applets Never truly integrated into browsers
  29. 29. Jay Phelps | @_jayphelps Why not integrate the JVM or CLR? misaligned goals, mostly related to validation/compiling
  30. 30. Jay Phelps | @_jayphelps Portable Native Client (PNaCl) lead by Google
  31. 31. Jay Phelps | @_jayphelps asm.js lead by Mozilla
  32. 32. size_t strlen(char *ptr) { char *curr = ptr; while (*curr != 0) { curr++; } return (curr - ptr); } "use asm" function strlen(ptr) { ptr = ptr|0; var curr = 0; curr = ptr; while (MEM8[curr]|0 != 0) { curr = (curr + 1)|0; } return (curr - ptr)|0; } asm.jsC
  33. 33. ! Jay Phelps | @_jayphelps WebAssembly !
  34. 34. Jay Phelps | @_jayphelps WebAssembly is an unprecedented collaboration
  35. 35. Jay Phelps | @_jayphelps The first open and standardized bytecode
  36. 36. Jay Phelps | @_jayphelps Is it going to kill JavaScript?
  37. 37. Jay Phelps | @_jayphelps Is it going to kill JavaScript?
  38. 38. Jay Phelps | @_jayphelps Nope!
  39. 39. Jay Phelps | @_jayphelps Will we compile JavaScript to WebAssembly?
  40. 40. Jay Phelps | @_jayphelps JavaScript is an extremely dynamic language
  41. 41. Jay Phelps | @_jayphelps Fully spec compliant JavaScript compiled to WebAssembly would be slower
  42. 42. Jay Phelps | @_jayphelps …but a strict subset of JavaScript could be fast!
  43. 43. Jay Phelps | @_jayphelps WebAssembly v1 MVP is best suited for languages like C/C++ and Rust
  44. 44. Jay Phelps | @_jayphelps Ideal for relatively low-level, system languages Very little dynamic features at run-time, no GC
  45. 45. Jay Phelps | @_jayphelps Some modern features of C++ don’t perform ideal
  46. 46. Jay Phelps | @_jayphelps Exceptions are the most common example
  47. 47. Jay Phelps | @_jayphelps But other languages are already supported, and more planned Things like Go, .NET, Java, OCaml, and even new ones
  48. 48. Jay Phelps | @_jayphelps WebAssembly will impact language design and implementation
  49. 49. Jay Phelps | @_jayphelps The Web requires unique considerations
  50. 50. Jay Phelps | @_jayphelps Rust team has specifically called out WebAssembly as a priority
  51. 51. Jay Phelps | @_jayphelps File sizes as well as lazy-loading/code splitting, caching, etc
  52. 52. Jay Phelps | @_jayphelps Shared libraries Traditional platforms like iOS/Android/macOS/ Windows have more robust stdlibs and UI toolkits
  53. 53. Jay Phelps | @_jayphelps Offline Caching story much more complex than desktop
  54. 54. Jay Phelps | @_jayphelps Interop with JavaScript Languages which better interop with JS have major advantage
  55. 55. Jay Phelps | @_jayphelps Promising: Dart, Elm, Reason Languages designed for the Web
  56. 56. Jay Phelps | @_jayphelps a TypeScript-like language? AssemblyScript is an early example
  57. 57. Jay Phelps | @_jayphelps export function factorial(n: i32): i32 { if (n == 0) { return 1; } else { return n * factorial(n - 1); } } AssemblyScript
  58. 58. Jay Phelps | @_jayphelps When should I target WebAssembly right now?
  59. 59. Jay Phelps | @_jayphelps Heavily CPU-bound number computations
  60. 60. Jay Phelps | @_jayphelps Games both Unity and Unreal Engine offer support
  61. 61. Jay Phelps | @_jayphelps Using existing portable code e.g. video/audio decoders and other processing
  62. 62. Jay Phelps | @_jayphelps bcrypt OpenCV mcl bls web-dsp hunspell XSalsa20 GDAL SPHINCS NTRUxxHash RLWE McEliece Zopfli SIDH ttf2woff2
  63. 63. Jay Phelps | @_jayphelps Zoom for Web client Video conferencing powered by WebAssembly, video/audio decoding off the main thread
  64. 64. react-native-dom (not react-native-web)
  65. 65. Jay Phelps | @_jayphelps Web UI developers are probably already using WebAssembly without knowing it!
  66. 66. Jay Phelps | @_jayphelps source-map npm package 10.9x faster! used by Firefox, Babel, create-react-app, LESS, etc
  67. 67. Jay Phelps | @_jayphelps Other use cases are just around the corner
  68. 68. Jay Phelps | @_jayphelps What was that binary stuff?
  69. 69. int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } } 00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B
  70. 70. 00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B
  71. 71. 00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B
  72. 72. 00 61 73 6D 01 00 00 00 01 86 80 80 80 00 01 60 01 7F 01 7F 03 82 80 80 80 00 01 00 06 81 80 80 80 00 00 0A 9D 80 80 80 00 01 97 80 80 80 00 00 20 00 41 00 46 04 40 41 01 0F 0B 20 00 41 01 6B 10 00 20 00 6C 0B
  73. 73. 03 82 80 80 80 0 81 80 80 80 00 0 80 80 00 01 97 8 00 20 00 41 00 4
  74. 74. 03 82 80 80 80 0 81 80 80 80 00 0 80 80 00 01 97 8 00 20 00 41 00 4
  75. 75. 03 82 80 80 80 0 81 80 80 80 00 0 80 80 00 01 97 8 00 20 00 41 00 4
  76. 76. Jay Phelps | @_jayphelps Binary can be a little intimidating
  77. 77. Jay Phelps | @_jayphelps Protip: don't worry about it (unless of course, you want to)
  78. 78. Jay Phelps | @_jayphelps Tooling will eventually make it a non-issue
  79. 79. Jay Phelps | @_jayphelps Textual representation to the rescue!
  80. 80. Jay Phelps | @_jayphelps (func $factorial (param $n i32) (result i32) get_local $n i32.const 0 i32.eq if $if0 i32.const 1 return end $if0 get_local $n i32.const 1 i32.sub call $factorial get_local $n i32.mul )
  81. 81. Jay Phelps | @_jayphelps (func $factorial (param $n i32) (result i32) get_local $n i32.const 0 i32.eq if $if0 i32.const 1 return end $if0 get_local $n i32.const 1 i32.sub call $factorial get_local $n i32.mul )
  82. 82. Jay Phelps | @_jayphelps Let's learn the fundamentals
  83. 83. Jay Phelps | @_jayphelps WebAssembly is a stack machine
  84. 84. Jay Phelps | @_jayphelps ...what's a stack machine?
  85. 85. Jay Phelps | @_jayphelps a data structure with two operations: push and pop Stack
  86. 86. Jay Phelps | @_jayphelps stack machine: instructions on a stack
  87. 87. Jay Phelps | @_jayphelps Why a stack machine? instead of AST, SSA, or register machine
  88. 88. Jay Phelps | @_jayphelps Smaller binary encoding, easier and faster single pass verification and VM implementation
  89. 89. 1 + 2
  90. 90. i32.add 0x6a opcode mnemonics 01101010
  91. 91. i32.const 1 i32.const 2 i32.add
  92. 92. stack i32.const 1 i32.const 2 i32.add
  93. 93. i32.const 1 i32.const 2 i32.add i32.const 1 stack 1
  94. 94. i32.const 1 i32.const 2 i32.add i32.const 1 stack 1
  95. 95. i32.const 1 i32.const 2 i32.add i32.const 2 stack 2 1
  96. 96. i32.const 1 i32.const 2 i32.add i32.const 2 stack 2 1
  97. 97. i32.const 1 i32.const 2 i32.addi32.add stack 1 2
  98. 98. i32.const 1 i32.const 2 i32.addi32.add stack 1 2
  99. 99. i32.const 1 i32.const 2 i32.addi32.add stack 3
  100. 100. i32.const 1 i32.const 2 i32.addi32.add stack 3
  101. 101. i32.const 1 i32.const 2 i32.add Jay Phelps | @_jayphelps
  102. 102. i32.const 1 i32.const 2 i32.add call $log Jay Phelps | @_jayphelps
  103. 103. Jay Phelps | @_jayphelps What's missing?
  104. 104. Jay Phelps | @_jayphelps Direct access to Host APIs (e.g. the DOM) no direct access to sys calls, you have to call into JavaScript
  105. 105. Jay Phelps | @_jayphelps Garbage collection necessary for better interop with JavaScript and WebIDL (e.g. the DOM)
  106. 106. Jay Phelps | @_jayphelps Multi-threading SharedArrayBuffer re-enabled in Chrome 68
  107. 107. Jay Phelps | @_jayphelps Single Instruction Multiple Data (SIMD) Hardware parallelization of vector computations
  108. 108. Jay Phelps | @_jayphelps Zero-cost exceptions someday maybe even Algebraic Effects (!!!)
  109. 109. Jay Phelps | @_jayphelps There's more, but advancing quickly!
  110. 110. Jay Phelps | @_jayphelps How do I get started?
  111. 111. Jay Phelps | @_jayphelps webassembly.org
  112. 112. Jay Phelps | @_jayphelps https://github.com/mbasso/awesome-wasm
  113. 113. Supported in all modern browsers
  114. 114. Jay Phelps | @_jayphelps The revolution is just beginning
  115. 115. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  116. 116. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web?
  117. 117. Jay Phelps | @_jayphelps The first open and standardized bytecode
  118. 118. Jay Phelps | @_jayphelps WebAssembly is not just for the Web!
  119. 119. ewasm Etherium-flavored WebAssembly VM for running distributed smart contracts
  120. 120. rianhunter/wasmjit VM and Linux kernel module for running WebAssembly in “ring 0”
  121. 121. nebulet microkernel that runs WebAssembly exclusively
  122. 122. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  123. 123. Jay Phelps | @_jayphelps Efficient, safe, low-level bytecode for the Web
  124. 124. Jay Phelps | @_jayphelps Thanks! @_jayphelps
  125. 125. Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ webassembly-intro

×