Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby & WebAssembly Introduction

Yuta Saito
November 11, 2022

Ruby & WebAssembly Introduction

Yuta Saito

November 11, 2022
Tweet

More Decks by Yuta Saito

Other Decks in Programming

Transcript

  1. RubyWorld Conference 2022 Ruby & WebAssembly Introduction Yuta Saito (@kateinoigakukun)

  2. About me • Yuta Saito / @kateinoigakukun • ૣҴాେֶ جװཧ޻ֶ෦

    ৘ใཧ޻ֶՊ4೥ • ύʔτλΠϜ։ൃऀ @ • CRubyͷWebAssembly/WASIϝϯςφ
  3. WebAssembly (Wasm) • ϒϥ΢βʹ࣮૷͞Ε͍ͯΔɺϙʔλϒϧͳ࣮ߦόΠφϦܗࣜ • Google Earth, Figma, GoodNotes, etc..

    Introduction
  4. WebAssembly (Wasm) • CPUΞʔΩςΫνϟʹґଘ͠ͳ͍ • ιʔεݴޠʹґଘ͠ͳ͍ • ϗετ؀ڥ΁ͷΞΫηε੍ݶ • ʢͦͦ͜͜ʣߴ଎

    https://hacks.mozilla.org/2017/02/creating-and-working-with-webassembly-modules/ ಛ௃
  5. WebAssembly (Wasm) • σβΠϯॳظ͔Βϒϥ΢βҎ֎ͷ؀ڥʹ΋ϥϯλΠϜΛຒΊࠐΉ͜ͱΛ૝ఆ Webϒϥ΢βҎ֎Ͱ΋ศར https://github.com/WebAssembly/design/commit/070f56c5c59030e2d735973f3e10dbe2c87366db

  6. WebAssembly (Wasm) • ϒϥ΢β͔Βಠཱͨ͠WebAssemblyϥϯλΠϜ࣮૷͕ଟ਺ • Wasmtime, WAMR, Wasmer, etc… •

    ΞϓϦέʔγϣϯʹ૊ΈࠐΈ΍͍͢ (like mruby) • ϢʔβʹΑΔʮ৴པͰ͖ͳ͍ϓϩάϥϜʯΛೖྗ͢Διϑτ΢ΣΞͰศར • ྫ) ϓϥάΠϯγεςϜɺαʔόʔϨεɺetc… Webϒϥ΢βҎ֎Ͱ΋ศར
  7. WebAssembly (Wasm) • ݴޠଆ • WasmʹίϯύΠϧͰ͖Ε͹ɺ༷ʑͳ؀ڥͰಈ͔ͤΔ • ϓϥοτϑΥʔϜଆ • WasmϥϯλΠϜ͑͋͞Ε͹ɺ༷ʑͳݴޠΛαϙʔτ͢Δ͜ͱ͕Ͱ͖Δ

    ݴޠ΋ϓϥοτϑΥʔϜ΋خ͍͠ ϓϩάϥϜަ׵ܗࣜʹͽͬͨΓ
  8. ϓϩάϥϜͷ഑෍୯Ґ Computer Hypervisor OS OS OS OS Libs Libs Libs

    App App App Computer OS Docker Libs Libs Libs App App App Computer OS WebAssembly Runtime App App App VMΠϝʔδ ίϯςφ .wasm
  9. Ruby on WebAssembly • RubyΠϯλϓϦλ (CRuby) ΛWebAssemblyʹίϯύΠϧ • ωΠςΟϒͱ΄΅ಉ͡ػೳΛఏڙ •

    Ruby͕ϒϥ΢β/༷ʑͳWasm؀ڥͰಈ͘Α͏ʹʂ • Ͳ͜Ͱ΋Ruby
  10. ͜Ε·ͰͷCRubyΛWebAssemblyͰಈ͔͢औΓ૊Έ emrubyʢ͍ʔ͑ΉΔͼʔʣ • EmscriptenπʔϧνΣΠϯͰίϯύΠϧ͞ΕͨCRuby • ϒϥ΢βͰͷར༻͕લఏ Emscripten ϒϥ΢β֎Ͱಈ͔ͤͳ͍ WASI ඪ४Խ͞Ε͓ͯΓɺ


    ϒϥ΢β֎Ͱ΋αϙʔτ͞ΕͯΔ
  11. None
  12. Ruby on WebAssembly <html> <script src="https://cdn.jsdelivr.net/npm/ruby-head- [email protected]/dist/browser.script.iife.js"></script> <script type="text/ruby"> puts

    "Hello, world!" </script> </html>
  13. https://kateinoigakukun.github.io/jupyterlite-ruby-kernel

  14. https://kateinoigakukun.github.io/jupyterlite-ruby-kernel

  15. ՝୊ ίʔυαΠζ • RubyεΫϦϓτͷαΠζ: 22MB • ؆୯ͳMini fi cation ->

    18MB • RubyΠϯλϓϦλͷαΠζ: 8.2MB • Asyncifyલ: 5.9MB
  16. ՝୊ ىಈ࣌ؒ • RubyεΫϦϓτͷ࣮ߦ·Ͱʹ60ms • ࢀߟɿJSΤϯδϯʢSpiderMonkeyʣ͸6ms https://bytecodealliance.org/articles/wasmtime-10-performance

  17. ·ͱΊ • Ruby 3.2Ͱ͸WebAssembly/WASIʹରԠ • ʮͲ͜Ͱ΋Rubyʯ΁ͷ1εςοϓ