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
130
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
28
Pkl/2024-04-17-llt31
ottijp
0
65
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
130
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
210
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
130
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
140
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
130
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
73
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
88
Other Decks in Programming
See All in Programming
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
120
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
650
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
110
Ruby on cygwin 2025-02
fd0
0
150
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
7
700
Unity Android XR入門
sakutama_11
0
160
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
120
Spring gRPC について / About Spring gRPC
mackey0225
0
220
2024年のWebフロントエンドのふりかえりと2025年
sakito
3
250
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
270
Grafana Cloudとソラカメ
devoc
0
170
GoとPHPのインターフェイスの違い
shimabox
2
190
Featured
See All Featured
RailsConf 2023
tenderlove
29
1k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
410
Rails Girls Zürich Keynote
gr2m
94
13k
GitHub's CSS Performance
jonrohan
1030
460k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Unsuck your backbone
ammeep
669
57k
Why Our Code Smells
bkeepers
PRO
336
57k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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