Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
wasmer/2021-02-10-llt19
Search
Satoshi SAKAO
February 10, 2021
Programming
1
110
wasmer/2021-02-10-llt19
社内のLTイベント「えるLT Vol.19 オンライン」で発表した資料です
Satoshi SAKAO
February 10, 2021
Tweet
Share
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Pkl/2024-04-17-llt31
ottijp
0
18
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
81
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
0
66
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
110
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
98
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
110
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
53
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
60
ncurses/2021-05-12-llt21
ottijp
0
150
Other Decks in Programming
See All in Programming
CQRS meets modern Java
simas
PRO
2
480
An adventure of Happy Eyeballs
coe401_
1
440
RailsConf 2024: Riffing on Rails: sketch your way to better designed code
kaspth
1
220
[RailsConf Detroit 2024] Ruby on Fails - effective error handling with Rails conventions
talyssonoc
0
300
地方こそサーバーレス、その意義に迫るサーバーレスPHP / Serverless PHP: The Rural Areas, and Why Serverless PHP Matters
seike460
PRO
2
110
Effectで作る堅牢でスケーラブルなAPIゲートウェイ / Robust and Scalable API Gateway Built on Effect
yasaichi
7
1.2k
Unlocking Potential of Property Based Testing with Ractor
ohbarye
2
1.4k
Enjoy Creative Coding with Ruby (RubyKaigi2024)
chobishiba
0
1.5k
JavaScript Closure
asoluka
0
2k
slog登場に伴うloggerの取り回し手法の見直し / kamakura.go #6
arthur1
0
180
Let's use LLMs from Ruby 〜 Refine RBS types using LLM 〜
kokuyouwind
0
210
Good first issues of TypeProf
mame
4
1.1k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
21
2k
We Have a Design System, Now What?
morganepeng
43
6.8k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
The Language of Interfaces
destraynor
151
23k
Product Roadmaps are Hard
iamctodd
45
9.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
649
58k
Building an army of robots
kneath
300
42k
GitHub's CSS Performance
jonrohan
1025
450k
Embracing the Ebb and Flow
colly
80
4.2k
For a Future-Friendly Web
brad_frost
172
9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Transcript
wasmer Satoshi SAKAO えるLT Vol.19 2021-02-10 1
話すひと 2 🏢 インフォコム株式会社 品質マネジメント推進室 👨🔧 ソフトウェアエンジニア 🛠 JS (ES6)
/ Node.js / GCP / IoT / iOS (Swift) 💖 猫,テクテクライフ(ランク: 17) Satoshi SAKAO @ottijp
wasm • わずむ • = WebAssembly • Webブラウザ上で動くバイナリ命令フォーマット • プログラミング言語間におけるポータビリティを実現
• 2019年5月に正式にWeb標準化 3
wasm 4 { js } <html> browsers programming langs
wasm • Pros • jsに比べ,構文解析や実行がネイティブ並みに早く軽量 • お好みのプログラミング言語を使える • ビジネス上のモチベーション •
Webブラウザにおける特定処理の高速化 • 既存資産(他言語実装)の利用 5
wasmer • スタンドアロンなwasmランタイムのひとつ • Windows, Mac, Linux, FreeBSDで利用可能 • 先月1.0がリリースされた
• プラガブルコンパイラ: singlepass, cranelift, LLVM • 事前コンパイル可能 6
wasmer 7 { js } <html> browsers wasmer OS WASI
wasmer • Pros • 用途に応じたコンパイラの選択 • 各プログラミング言語への組み込み • ビジネス上のモチベーション •
Web, IoT, エッジコンピューティングなどに跨る ユニバーサルバイナリの必要性 • サンドボックス動作でセキュア 8
今回やったこと • swiftwasmでswiftからwasmを作る • wasmerでそれをスタンドアロンで動かす • 色々やってみたけど,うまくいかなかったこと (´;ω;`)ブワッ • wasmerでwasmを他の言語に組み込んで使う
• 実行速度を比較してwasmすげー!ってなる 9
swiftwasmで作ったwasmをwasmerで動かす 10 @_cdecl("tetranacci") func tetranacci(_ n: Int) -> Int {
switch n { case 1, 2, 3: return 0 case 4: return 1 default: return [1, 2, 3, 4].reduce(0) {$0 + tetranacci(n - $1)} } } print(tetranacci(Int(CommandLine.arguments[1])!)) ςτϥφονΛܭࢉ͢Δ Main.swift
swiftwasmで作ったwasmをwasmerで動かす 11 $ swiftc -target wasm32-unknown-wasi -o main.wasm Main.swift $
ls -lh main.wasm -rwxr-xr-x@ 1 otti staff 9.8M Feb 6 22:24 main.wasm* $ file main.wasm main.wasm: WebAssembly (wasm) binary module version 0x1 (MVP)
swiftwasmで作ったwasmをwasmerで動かす 12 $ wasmer main.wasm 10 29 ςτϥφονͷୈ10߲29
wasmerでwasmを他の言語に組み込んで使う • pythonで作ったwasmを読み込んで使おうと思ったけど, wasi_snapshot_preview1 のインポートが解決できなくて うまくいかんかった.(´;ω;`)ブワッ 13 $ python main.py
Traceback (most recent call last): File "main.py", line 6, in <module> instance = Instance(module) RuntimeError: Error while importing "wasi_snapshot_preview1"."proc_exit": unknown import. Expected Function(FunctionType { params: [I32], results: [] })
実行速度を比較してwasmすげー!ってなる • そこまで速ない (´;ω;`)ブワッ 14 対象 実行速度 (sec) swift executable
最適化なし 6.9 最適化有り 0.4 wasmer JIT LLVM 35.0 cranelift 7.5 singlepass 8.8 wasmer precompiled LLVM 3.7 cranelift 7.0 singlepass 8.9 ςτϥφον28߲Λܭࢉ
まとめ • wasm, wasmerを手を動かして理解できた • ユニバーサルバイナリとしての利点を検証できなかった (他言語への組み込み) • 軽量で高速というwasmの利点は検証できなかった 15
まとめ cont. • wasmを単純なユニバーサルバイナリとして捉えて モジュール化するのは違うと感じた(制約が多い) • wasmの型はi32, i64, f32, f64のみ
• 文字列等を含むinport/exportはmemoryを公開する (swiftwasmでの方法がわからんかった(できない?)) • webブラウザ以外におけるホスト環境(wasm利用モジュール)との 通信はまだ発展途上? • ホスト環境との通信やWASIのこと調べてると, がねこさんの記事がよくヒットするw 16
まとめ cont. 17 https://qiita.com/massie_g/items/c663095759a80c53c126
ブログ書いた 18 https://blog.ottijp.com/2021/02/07/wasmer/
19 Appendix
wasm • 作る手段 • emscripten • swiftwasm • llc &&
wasm-ld • etc • 類似技術 • asm.js • PNaCl 20
wasmer • 類似技術 • wasmtime • Lucet • Krustlet 21
swiftwasmのインストール • Setup - Swift and WebAssembly • https://book.swiftwasm.org/getting-started/setup.html •
swiftwasmのツールチェインがインストールされるので, そのツールチェインを使う • $ xcrun --toolchain swiftwasm swiftc --version 22
wasmerのインストール • $ curl https://get.wasmer.io -sSfL | sh 23
refs • WebAssembly • https://webassembly.org/ • WebAssembly - Wikipedia •
https://ja.wikipedia.org/wiki/WebAssembly • WebAssembly の概要 - WebAssembly | MDN • https://developer.mozilla.org/ja/docs/WebAssembly/Concepts • A WebAssembly Compiler tale. How we abstracted our API to be… | by Syrus Akbary | Wasmer | Medium • https://medium.com/wasmer/a-webassembly-compiler-tale-9ef37aa3b537 • 【WebAssembly初心者必読】バイナリコードを使って「 WebAssembly 」の基礎を徹底解説してみた! | 株式会 社ヌーラボ(Nulab inc.) • https://nulab.com/ja/blog/nulab/basic-webassembly-begginer/ • SwiftWasm - compile Swift to WebAssembly • https://swiftwasm.org/ 24
refs cont. • WebAssemblyをWin/Mac/Linuxで実行可能なランタイム「Wasmer 1.0」正式リリース。事前コンパイル による高速起動やクロスコンパイルなどにも対応 - Publickey • https://www.publickey1.jp/blog/21/webassemblywinmaclinuxwasmer_10.html
• wasmerio/wasmer: 🚀 The leading WebAssembly Runtime supporting WASI and Emscripten • https://github.com/wasmerio/wasmer • WebAssemblyをブラウザの外で動かすWasmerを触ってみた • https://zenn.dev/koduki/articles/f1b342079788be • Compiling C to WebAssembly without Emscripten — surma.dev • https://surma.dev/things/c-to-webassembly/ • Node.jsでつくるNode.js-WASMコンパイラ - もくじ - Qiita • https://qiita.com/massie_g/items/c663095759a80c53c126 • Generalizations of Fibonacci numbers - Wikipedia • https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers 25