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
140
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
Testcontainers/2024-11-20-llt32
ottijp
0
43
Pkl/2024-04-17-llt31
ottijp
0
76
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
140
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
240
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
140
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
150
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
140
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
81
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
96
Other Decks in Programming
See All in Programming
20250429 - CNTUG Meetup #67 / DevOps Taiwan Meetup #69 - Deep Dive into Tetragon: Building Runtime Security and Observability with eBPF
tico88612
0
190
開発者フレンドリーで顧客も満足?Platformの秘密
algoartis
0
230
OpenTelemetryで始めるベンダーフリーなobservability / Vendor-free observability starting with OpenTelemetry
seike460
PRO
0
110
私のRubyKaigi 2025 Kaigi Effect / My RubyKaigi 2025 Kaigi Effect
chobishiba
1
140
In geheimer Mission: AI Agents entwickeln
joergneumann
0
120
監視 やばい
syossan27
12
10k
UMAPをざっくりと理解 / Overview of UMAP
kaityo256
PRO
3
1.6k
AWS Summit Hong Kong 2025: Reinventing Programming - How AI Transforms Our Enterprise Coding Approach
dwchiang
0
150
知識0からカンファレンスやってみたらこうなった!
syossan27
5
280
파급효과: From AI to Android Development
l2hyunwoo
0
170
Flutterでllama.cppをつかってローカルLLMを試してみた
sakuraidayo
0
150
実践Webフロントパフォーマンスチューニング
cp20
45
10k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
5.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
84
5.5k
A designer walks into a library…
pauljervisheath
205
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Done Done
chrislema
184
16k
Optimising Largest Contentful Paint
csswizardry
37
3.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Building Adaptive Systems
keathley
41
2.5k
It's Worth the Effort
3n
184
28k
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.5k
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