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)

    View full-size slide

  2. About me
    • Yuta Saito / @kateinoigakukun

    • ૣҴాେֶ جװཧ޻ֶ෦ ৘ใཧ޻ֶՊ4೥

    • ύʔτλΠϜ։ൃऀ @

    • CRubyͷWebAssembly/WASIϝϯςφ

    View full-size slide

  3. WebAssembly (Wasm)
    • ϒϥ΢βʹ࣮૷͞Ε͍ͯΔɺϙʔλϒϧͳ࣮ߦόΠφϦܗࣜ

    • Google Earth, Figma, GoodNotes, etc..
    Introduction

    View full-size slide

  4. WebAssembly (Wasm)
    • CPUΞʔΩςΫνϟʹґଘ͠ͳ͍

    • ιʔεݴޠʹґଘ͠ͳ͍

    • ϗετ؀ڥ΁ͷΞΫηε੍ݶ

    • ʢͦͦ͜͜ʣߴ଎
    https://hacks.mozilla.org/2017/02/creating-and-working-with-webassembly-modules/
    ಛ௃

    View full-size slide

  5. WebAssembly (Wasm)
    • σβΠϯॳظ͔Βϒϥ΢βҎ֎ͷ؀ڥʹ΋ϥϯλΠϜΛຒΊࠐΉ͜ͱΛ૝ఆ
    Webϒϥ΢βҎ֎Ͱ΋ศར
    https://github.com/WebAssembly/design/commit/070f56c5c59030e2d735973f3e10dbe2c87366db

    View full-size slide

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

    • Wasmtime, WAMR, Wasmer, etc…

    • ΞϓϦέʔγϣϯʹ૊ΈࠐΈ΍͍͢ (like mruby)

    • ϢʔβʹΑΔʮ৴པͰ͖ͳ͍ϓϩάϥϜʯΛೖྗ͢Διϑτ΢ΣΞͰศར

    • ྫ) ϓϥάΠϯγεςϜɺαʔόʔϨεɺetc…
    Webϒϥ΢βҎ֎Ͱ΋ศར

    View full-size slide

  7. WebAssembly (Wasm)
    • ݴޠଆ

    • WasmʹίϯύΠϧͰ͖Ε͹ɺ༷ʑͳ؀ڥͰಈ͔ͤΔ

    • ϓϥοτϑΥʔϜଆ

    • WasmϥϯλΠϜ͑͋͞Ε͹ɺ༷ʑͳݴޠΛαϙʔτ͢Δ͜ͱ͕Ͱ͖Δ
    ݴޠ΋ϓϥοτϑΥʔϜ΋خ͍͠
    ϓϩάϥϜަ׵ܗࣜʹͽͬͨΓ

    View full-size slide

  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

    View full-size slide

  9. Ruby on WebAssembly
    • RubyΠϯλϓϦλ (CRuby) ΛWebAssemblyʹίϯύΠϧ

    • ωΠςΟϒͱ΄΅ಉ͡ػೳΛఏڙ

    • Ruby͕ϒϥ΢β/༷ʑͳWasm؀ڥͰಈ͘Α͏ʹʂ

    • Ͳ͜Ͱ΋Ruby

    View full-size slide

  10. ͜Ε·ͰͷCRubyΛWebAssemblyͰಈ͔͢औΓ૊Έ
    emrubyʢ͍ʔ͑ΉΔͼʔʣ
    • EmscriptenπʔϧνΣΠϯͰίϯύΠϧ͞ΕͨCRuby

    • ϒϥ΢βͰͷར༻͕લఏ
    Emscripten
    ϒϥ΢β֎Ͱಈ͔ͤͳ͍
    WASI
    ඪ४Խ͞Ε͓ͯΓɺ

    ϒϥ΢β֎Ͱ΋αϙʔτ͞ΕͯΔ

    View full-size slide

  11. Ruby on WebAssembly






    <br/><br/><br/>puts "Hello, world!"<br/><br/><br/>



    View full-size slide

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

    View full-size slide

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

    View full-size slide

  14. ՝୊
    ίʔυαΠζ

    • RubyεΫϦϓτͷαΠζ: 22MB

    • ؆୯ͳMini
    fi
    cation -> 18MB

    • RubyΠϯλϓϦλͷαΠζ: 8.2MB

    • Asyncifyલ: 5.9MB

    View full-size slide

  15. ՝୊
    ىಈ࣌ؒ

    • RubyεΫϦϓτͷ࣮ߦ·Ͱʹ60ms

    • ࢀߟɿJSΤϯδϯʢSpiderMonkeyʣ͸6ms
    https://bytecodealliance.org/articles/wasmtime-10-performance

    View full-size slide

  16. ·ͱΊ
    • Ruby 3.2Ͱ͸WebAssembly/WASIʹରԠ

    • ʮͲ͜Ͱ΋Rubyʯ΁ͷ1εςοϓ

    View full-size slide