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
53
Pkl/2024-04-17-llt31
ottijp
0
81
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
150
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
260
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
150
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
160
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
140
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
84
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
100
Other Decks in Programming
See All in Programming
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
1
2.7k
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
150
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
5つのアンチパターンから学ぶLT設計
narihara
1
150
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
120
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
0
330
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
35
6.2k
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
140
CursorはMCPを使った方が良いぞ
taigakono
1
220
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
590
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
120
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
400
Featured
See All Featured
Faster Mobile Websites
deanohume
307
31k
Gamification - CAS2011
davidbonilla
81
5.3k
Being A Developer After 40
akosma
90
590k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
A Tale of Four Properties
chriscoyier
160
23k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Six Lessons from altMBA
skipperchong
28
3.9k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
KATA
mclloyd
30
14k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
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