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
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
470
NPOでのDevinの活用
codeforeveryone
0
460
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
210
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
240
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
260
5つのアンチパターンから学ぶLT設計
narihara
1
130
C++20 射影変換
faithandbrave
0
550
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
710
Is Xcode slowly dying out in 2025?
uetyo
1
230
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
300
PicoRuby on Rails
makicamel
2
110
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
380
Featured
See All Featured
Facilitating Awesome Meetings
lara
54
6.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
We Have a Design System, Now What?
morganepeng
53
7.7k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
680
Embracing the Ebb and Flow
colly
86
4.7k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
800
Producing Creativity
orderedlist
PRO
346
40k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
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